Gradle依赖性导致错误"无效的幻数"

Jui*_*iCe 7 git android magic-numbers proguard gradle

我在GitHub上有一个项目,我在家里的办公室工作.大约2个月,它在两台机器上运行良好.两个星期前,它停止在家用电脑上运行,但在我的工作电脑上仍能正常工作.

这是我得到的错误:

:app:shrinkDebugMultiDexComponents FAILED

FAILURE:构建因异常而失败.

  • 出了什么问题:任务执行失败':app:shrinkDebugMultiDexComponents'.java.io.IOException:无法读取[D:\ dev\gitRepo\app\android\app\build\intermediates\multi-dex\debug\allclasses.jar](无法处理类[__MACOSX/com/stripe /android/._BuildConfig.class](类中无效的幻数[51607]))
  • 尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行以获取更多日志输出.

stripe给我错误的包是你可以在这里找到的第三方库.我将它作为我的build.gradle文件中的依赖项完全按照他们的说法列出.

compile 'com.stripe:stripe-android:+'
Run Code Online (Sandbox Code Playgroud)

我已经注释掉所有stripe与该应用程序相关的代码并且应用程序运行完全正常,所以我知道它与我如何处理该包有关.

不幸的是,我不记得我做了什么让这个停止工作.我确实认为在发生这一周之前的一周我升级了Android Studio,并花了相当多的时间来搞乱ProGuard配置.

我尝试过的:

  • master在没有进行任何ProGuard更改的分支上工作.
  • 卸载并重新安装Android Studio
  • 重新克隆git repo
  • 安装API 17(eclipse的条纹需要这个.不是Studio,但我试了一下).
  • 联系条形客户支持,但他们没有任何线索.
  • 这个堆栈溢出帖子.但是,没有任何Mac计算机触及过这个项目,也没有我个人压缩任何相关的东西stripe.
  • 从这里,将幻数从十六进制转换为ASCII.结果是我不认识的Q`.

我认为这可能与我为ProGuard所做的事情有关,但我不明白如何做.我和Proguard的工作完全不同,有一个干净的AndroidStudio安装,有一个干净的存储库克隆,当我在办公室时,项目仍然正常.

编辑

我在debugBuildType 上运行它.这些是我的3个gradle文件.第一个是整个项目,第二个是应用程序模块,第三个是本地android库模块.

项目build.gradle:buildscript {repositories {jcenter()maven {url'http: //download.crashlytics.com/maven '}} dependencies {classpath'com.android.tools.build:grad:1.2.3'classpath'com.crashlytics .tools.gradle:crashlytics-gradle:1.+'}}

allprojects {
    repositories {
        jcenter()
        maven{ url 'http://download.crashlytics.com/maven' }
    }
}
Run Code Online (Sandbox Code Playgroud)

Android应用程序模块 build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}


android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.app.android"
        renderscriptTargetApi 19
        renderscriptSupportModeEnabled true
        minSdkVersion 16
        targetSdkVersion 22
        multiDexEnabled = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            buildConfigField 'Boolean', 'enableCrashlytics', 'true'
        }
        debug {
            buildConfigField 'Boolean', 'enableCrashlytics', 'false'
        }
        adhoc {
            debuggable true
            signingConfig signingConfigs.debug
            buildConfigField 'Boolean', 'enableCrashlytics', 'true'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
}
dependencies {
    compile project(':localLibrary')
    compile 'com.facebook.android:facebook-android-sdk:3.21.1'
    compile 'commons-io:commons-io:2.4'
    compile 'com.github.bumptech.glide:glide:3.6.1'
    compile 'com.android.support:support-v4:22.0.1'
    compile 'com.google.android.gms:play-services-identity:8.1.0'
    compile 'com.google.android.gms:play-services-plus:8.1.0'
    compile 'com.google.android.gms:play-services-maps:8.1.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'io.card:android-sdk:5.0.1'
    compile 'com.stripe:stripe-android:+'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        transitive = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

本地Android库模块 build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22
        multiDexEnabled = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.1.0'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'com.android.support:multidex:1.0.0'
    compile group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5'
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'

}
Run Code Online (Sandbox Code Playgroud)

Jim*_*Jim 3

此问题可能与您运行的 Java 版本有关。我遇到了类似的问题,并发现使用 Java 8 进行构建。当我更改为 Java 7 时,这个构建问题得到了解决。

在 Android Studio 中转到

File -> Project Structure -> SDK Location
Run Code Online (Sandbox Code Playgroud)

应该JDK Location是 Java 1.7.x (Java 7)