I have been getting Top level exception in android studio, i am using appcompat and sliding menu library. I know i am getting the exception because of conflict of Android Support Libraries as explained in some of the previous threads in stackoverflow. I have tried All the the methods shown in threads like including configuraion etc.
here is my Build.gradle(root)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}
allprojects {
repositories {
jcenter()
}
}
Here is my Build.Gradle(App)
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
applicationId "com.danaraddi.cprograms"
minSdkVersion 8
targetSdkVersion 21
versionCode 9
versionName "7.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.2'
}
// animations
dependencies {
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.0#aar'
compile 'com.daimajia.androidanimations:library:1.0.8#aar'
}
// inject views
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.jakewharton:butterknife:5.1.2'
}
dependencies {
// Your other dependencies go here
compile project(':library')
}
Here is my Build.Gradle(Lib - SlidingMenu)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
Here is my Log Cat
Error:Execution failed for task ':app:dexDebug'.
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback;
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:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
PS : I Have places configuration in root,app build.gradle too , it builds successfully after a clean project and then after the same error.
Add
dexOptions {
preDexLibraries = false
}
instead of
dexOptions {
incremental true
}
to build.gradle file inside the android block
Related
For image processing i want to sync tessaract OCR in Android..i dont knw how to sync..!! when i tried to do some changes it shows "gradle sync failed"..
Here is setting.gradle and build.gradle
// setting.gradle:
include ':app'
include ':libraries:tess-two'
build.gradle of MyApplication:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.raghavan.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
}
build.gradle of tess-two:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
}
}
Help! Its my .gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "test.app.android.player"
minSdkVersion 15
targetSdkVersion 23
multiDexEnabled true
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
}
dependencies {
compile files('libs/android-support-v4-22.2.1.jar')
compile files('libs/android-support-v7-recyclerview-22.2.1.jar')
compile files('libs/applovin-6.1.5.jar')
compile files('libs/appodeal-1.14.6.jar')
compile files('libs/chartboost-6.2.0.jar')
compile files('libs/flurry-analytics-6.2.0.jar')
compile files('libs/inmobi-5.2.0.jar')
compile files('libs/my-target-4.2.0.jar')
compile files('libs/unity-ads-1.4.7.jar')
compile files('libs/yandex-metrica-2.30.jar')
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.android.support:multidex:1.0.0'
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
And i got this error in logcat see this: Error:Execution failed for task ':packageAllReleaseClassesForMultiDex'.
java.util.zip.ZipException: duplicate entry: android/support/v4/view/PagerAdapter.class
I dont find duplicate
You have to remove
compile files('libs/android-support-v4-22.2.1.jar')
The 'com.google.android.gms:play-services-ads:8.4.0' has a dependency with com.android.support:support-v4:23.0.0. In this way you adding twice the same class with different version.
Recently I'm trying to use LeakCanary to fix OOM(out of memory) issues for my Android app. And I added
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
to my build.gradle, following the instructions on LeakCanary website. After gradle build, I got
"/android-sdk/android-sdk_r22.6.2-linux/build-tools/21.1.1/aapt'' finished with non-zero exit value 1
This is part of my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'android'
apply plugin: 'maven'
android {
compileSdkVersion 19
buildToolsVersion '22.0.1'
defaultConfig {
multiDexEnabled true
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
res.srcDirs = ['res']
}
instrumentTest.setRoot('tests')
}
dexOptions {
jumboMode = true
preDexLibraries = false
javaMaxHeapSize = '2g'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
flatDir {
dirs 'libs'
}
maven {
url "http://XXXXX/nexus/content/repositories/releases"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'ShortcutBadger-1.0.1', ext: 'aar')
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
}
When I updated the CompileSDKVersion to 22 and buildToolsVersion to 22.0.1, it worked.
Hope this can help anyone having this problem.
I changed
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
to
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
As well as the CompileSDKVersion to 22 and buildToolsVersion to 22.0.1 as suggested by CherryWang https://stackoverflow.com/a/30496364/1247248
I got this from a comment in Gradle finished with non-zero exit value 1 (ic_launcher.png: error: Duplicate file)
After i added the 'com.github.carlonzo.stikkyheader:core:0.0.2-SNAPSHOT' library in my gradle file Im getting the error on build:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
here is my gradle.build file:
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://download.crashlytics.com/maven' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: "eclipse"
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://download.crashlytics.com/maven' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
android {
compileSdkVersion 21
buildToolsVersion "19.1.0"
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(":libraries:google-play-services-lib")
compile project(":libraries:pager-indicator-lib")
compile project(":libraries:apphance-library-1.9.11")
compile project(":libraries:dialog-manager-lib")
compile 'com.crashlytics.android:crashlytics:1.+'
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
signingConfigs {
release {
storeFile file(RELEASE_KEYSTORE_FILE)
storePassword System.getenv("PASSWORD_KEYSTORE")
keyAlias System.getenv("ALIAS_KEYSTORE_JB")
keyPassword System.getenv("PASSWORD_KEYSTORE")
}
debug {
storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
}
beta {
storeFile file(DEBUG_KEYSTORE_FILE_LOCAL)
}
}
buildTypes {
debug {
debuggable true
signingConfig android.signingConfigs.debug
applicationIdSuffix ".debug"
}
release {
signingConfig signingConfigs.release
}
beta {
debuggable true
signingConfig android.signingConfigs.debug
applicationIdSuffix ".beta"
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
release {
res.srcDirs = ['res_release']
}
beta {
res.srcDirs = ['res_beta']
}
instrumentTest.setRoot('test')
instrumentTest {
java.srcDirs = ['test']
}
}
lintOptions {
abortOnError false
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}
dependencies {
// compile 'com.android.support:support-annotations:20.0.0'
compile 'com.mixpanel.android:mixpanel-android:4.5.2'
compile 'com.android.support:multidex:1.0.0'
compile ('com.facebook.android:facebook-android-sdk:3.22.0')
{
exclude module: 'support-v4'
}
compile ('com.github.carlonzo.stikkyheader:core:0.0.2-SNAPSHOT')
{
exclude module: 'support-v4'
}
}
Any ideas on how to fix it ? Thanks
This happens because every dependency has its own dependency to the support library (or support.annotation in your case).
My suggestion is to replace the exclude module: 'support-v4' with a exclude group: 'com.android.support' . I would suggest you to exclude the group com.android.support to every dependency you added and declare your own dependency to the support library
I'm trying to use gradle to build my Android project wit Android Annotations but I still get errors. In my java classes AA is not found.
Also in gradle file I get some hints:
versionName "1.0" <- 'versionName' cannot be applied to '(java.lang.String)'
'main' in 'build' cannot be applied to '(groovy.lang.Closure)'
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'GENERATED_FOLDER']
resources.srcDirs = ['src/main/resources']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
Below is my full gradle script:
buildscript {
repositories {
mavenCentral()
}
dependencies {
// replace with the current version of the Android plugin
classpath 'com.android.tools.build:gradle:0.9.2'
// the latest version of the android-apt plugin
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
}
}
repositories {
mavenCentral()
mavenLocal()
}
apply plugin: 'android'
apply plugin: 'android-apt'
def AAVersion = '3.0.1'
dependencies {
// Android annotations
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support:appcompat-v7:19.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
// ORMLite
compile 'com.j256.ormlite:ormlite-android:4.46'
// Google Guava
compile 'com.google.guava:guava:16.0.1'
}
apt {
arguments {
androidManifestFile variant.processResources.manifestFile
resourcePackageName 'pl.grzeslowski.weaselmoney'
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'GENERATED_FOLDER']
resources.srcDirs = ['src/main/resources']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
}
This is log from my console in Android Studio:
Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0
:weasel_moneyWeaselMoney:help
Welcome to Gradle 1.10.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 6.111 secs
Process finished with exit code 0
Dont put your AA configuration on your General build.gradle
put it in your app folder inside build.gradle, look # this example
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
def AAVersion = '3.2'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName 'com.example.app'
logLevel 'TRACE' //Use this to get AA log
logAppenderConsole 'true' //Use this to get AA log
}
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
debug {
debuggable true
}
}
packagingOptions {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
}
dependencies {
//Libs
compile fileTree(dir: 'libs', include: ['*.jar'])
//Dependency
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1' //If you're using REST
compile 'com.google.code.gson:gson:1.7.2'
compile 'org.codepond:wizardroid:1.3.0'
//Android Annotations
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
}