0

I've been banging my head against this for a few hours now. I tried importing 2bard's AndroidPianoView as a library project (both PianoView and PianoViewExample inside) and they both have a support-v4 jar in their libs directory.

My project is in Android Studio.

Removing the jar from either or both directories does me no good, and I have tried following the solution in this popular question without success.

Here's the dependency tree from running gradle -q:app:dependencies:

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:22.2.1
|    \--- com.android.support:support-v4:22.2.1
|         \--- com.android.support:support-annotations:22.2.1
\--- project :PianoViewExample
     \--- project :PianoView

Here are the build.gradle files:

My Project

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.ajbowler.jamory"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile project(':PianoViewExample')
}

PianoView

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
       }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

PianoViewExample

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.library'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':PianoView')
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

Console Output

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v4/app/ActivityCompatHoneycomb;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2

What Happens when I exclude module: 'support-v4' in main project

buildscript {
    repositories {
        mavenCentral() // or jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.ajbowler.jamory"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile project(':PianoViewExample')
    compile('com.android.support:appcompat-v7:23.0.1') {
        configurations {
            all*.exclude group: 'com.android.support', module: 'support-v4'
            all*.exclude group: 'com.google.android.gms', module: 'play-services'
        }
    }
}

Output

Error:(8, 8) error: cannot access TaskStackBuilder
class file for android.support.v4.app.TaskStackBuilder not found
Error:(10, 5) error: method does not override or implement a method  from a supertype
Error:(12, 9) error: cannot find symbol variable super
Error:(13, 9) error: cannot find symbol method setContentView(int)
Error:(16, 5) error: method does not override or implement a method from a supertype
Error:(19, 9) error: cannot find symbol method getMenuInflater()
Error:(23, 5) error: method does not override or implement a method from a supertype
Error:(35, 16) error: cannot find symbol variable super
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

I would really appreciate some help on this. I have been unable to figure out where the issue has been coming from past exclude-ing the support jar from one of the PianoView modules, which hasn't worked.

Community
  • 1
  • 1
Andrew Bowler
  • 93
  • 1
  • 2
  • 7

1 Answers1

0

Yeah, just fixed that today. In my case it was a conflict between support v4 and support v7 in maven. All I did was to add the exclude flag for the support v4 in the support v7 tag of the main project.
I had to exclude the v4 from v7 because I was already using it(the import for the v4 is located 5 lines above in my pom file).
Example:
http://www.thedevline.com/2014/06/unexpected-top-level-exception.html?m=1
EDIT
Similar posts:
Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat.
Hope it helps.
Multiple dex files define Landroid/support/v4/ in android studio

Community
  • 1
  • 1
Andrei T
  • 2,985
  • 3
  • 21
  • 28
  • I have tried this before, excluding `'support-v4'` from the the support v7 tag in the main project (not the library project) and then it complains that a class file is missing inside the support v4 jar. – Andrew Bowler Sep 16 '15 at 21:18
  • post the message you get when you remove it. – Andrei T Sep 16 '15 at 21:19
  • There, it's posted towards the bottom. – Andrew Bowler Sep 16 '15 at 21:31
  • did you read the link I posted and added the v7 app compact?. Can you please post your final gradle file? – andrei 10 mins ago – Andrei T Sep 16 '15 at 21:49
  • Yes, I did read it and added the changes it recommended. Final gradle file posted towards the bottom. – Andrew Bowler Sep 16 '15 at 22:06
  • I added another link that is similar to this. I also restarted the android studio. More than that I cannot help you. It works for me and as it seems for everybody else. – Andrei T Sep 16 '15 at 22:19