Frustrating error after adding a simple Java Library (new Module in Android Studio). I've read many similar questions but cannot find any solution, anyone can help me?
Error:Execution failed for task ':KeepLinkMain:preDexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\Android\android-sdk\build-tools\19.1.0\dx.bat --dex --output C:...\AndroidStudioProjects\KeepLink\KeepLinkMain\build\intermediates\pre-dexed\debug\KeepLinkLib-d6db361e6605649280566ee9a3143d04322844dc.jar C:...\AndroidStudioProjects\KeepLink\KeepLinkLib\build\libs\KeepLinkLib.jar Error Code: 1 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000) at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472) at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406) at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388) at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251) at com.android.dx.command.dexer.Main.processClass(Main.java:665) at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634) at com.android.dx.command.dexer.Main.access$600(Main.java:78) at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572) at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284) at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166) at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144) at com.android.dx.command.dexer.Main.processOne(Main.java:596) at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264) 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) ...while parsing com/rmpt/keeplinklib/Constants.class 1 error; aborting
Main module build.gradle file
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
debuggable false
jniDebugBuild false
}
}
dexOptions {
incremental true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
productFlavors {
}
}
dependencies {
compile project(':KeepLinkLib')
compile files('lib/gson-2.2.4.jar')
}
Java Library build.gradle file
apply plugin: 'java'
For the experimental gradle edition, that uses a different syntax, you have to write it this way:
I ran into a similar issue and was able to resolve it by adding the following lines to the Java library's build.gradle below the
apply plugin:
line:I also had to remove the
compileOptions
block from within the main module's build.gradle