意外的顶级异常将新模块添加到Android Studio项目中

时间:2014-06-22 00:08:09

标签: android class exception

添加简单Java库(Android Studio中的新模块)后出现令人沮丧的错误。我已经阅读了很多类似的问题,但找不到任何解决方案,任何人都可以帮助我吗?

Error:Execution failed for task ':KeepLinkMain:preDexDebug'.
  

com.android.ide.common.internal.LoggedErrorException:无法运行命令:       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   错误代码:       1   输出:       意外的顶级例外情况:       com.android.dx.cf.iface.ParseException:错误的类文件魔术(cafebabe)或版本(0034.0000)           在com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)           在com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)           在com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)           在com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)           在com.android.dx.command.dexer.Main.processClass(Main.java:665)           在com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)           在com.android.dx.command.dexer.Main.access $ 600(Main.java:78)           在com.android.dx.command.dexer.Main $ 1.processFileBytes(Main.java:572)           在com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)           在com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)           在com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)           在com.android.dx.command.dexer.Main.processOne(Main.java:596)           在com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)           在com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)           在com.android.dx.command.dexer.Main.run(Main.java:230)           在com.android.dx.command.dexer.Main.main(Main.java:199)           在com.android.dx.command.Main.main(Main.java:103)       ...在解析com / rmpt / keeplinklib / Constants.class时       1错误;中止

主模块build.gradle文件

    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文件

apply plugin: 'java'

2 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,并且能够通过将以下行添加到apply plugin:行下面的Java库的build.gradle来解决它:

sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7

我还必须从主模块的build.gradle中删除compileOptions

答案 1 :(得分:1)

对于使用不同语法的实验性gradle版本,您必须以这种方式编写:

apply plugin: 'com.android.model.application'
//apply plugin: 'java' //do not include this line
model {
    android {
        compileOptions.with {
            sourceCompatibility = JavaVersion.VERSION_1_7
            targetCompatibility = JavaVersion.VERSION_1_7
        }
        ... //rest of gradle code
    }
}