Gradle dependency causing error “Invalid Magic Number”

99封情书 提交于 2019-12-08 17:38:23

问题


I have a project on GitHub that I work on both in the office at home. For about 2 months it was working fine on both machines. Then two weeks ago, it stopped running on my home PC, but still works fine on my work PC.

This is the error I get:

:app:shrinkDebugMultiDexComponents FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:shrinkDebugMultiDexComponents'. java.io.IOException: Can't read [D:\dev\gitRepo\app\android\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can't process class [__MACOSX/com/stripe/android/._BuildConfig.class] (Invalid magic number [51607] in class))
  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

The stripe package that is giving me errors is a 3rd party library that you can find here. I list it as a dependency in my build.gradle file exactly as they say to.

compile 'com.stripe:stripe-android:+'

I have commented out all code pertaining the stripe and the app runs completely fine, so I do know it has something to do with how I am handling that package.

Unfortunately I don't remember exactly what I had done to make this stop working. I do think that the week before this happened I upgraded Android Studio, and spent a considerable amount of time messing with ProGuard configurations.

What I have tried:

  • Working on the master branch where no ProGuard changes have been made.
  • Uninstalling and Reinstalling Android Studio
  • Re-cloning the git repo
  • Installing API 17 (stripe for eclipse requires this. Not Studio but I gave it a shot).
  • Contacting stripe customer support but they had no clue.
  • This stack overflow post. However, there is no Mac computer that has touched the project nor have I personally zipped anything related to stripe.
  • From here, converted the magic number from Hex to ASCII. The result was Q` which I do not recognize.

I think it may have something to do with something I did for ProGuard, but I don't understand how. I'm on a completely different branch than any Proguard work, with a clean AndroidStudio install, with a clean repository clone, and the project still works fine when I'm in the office.

EDIT

I am running this on the debug BuildType. These are my 3 gradle files. The first is for the entire Project, the second is for the Application Module, and the third is for a local android library Module.

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

allprojects {
    repositories {
        jcenter()
        maven{ url 'http://download.crashlytics.com/maven' }
    }
}

Android Application Module 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;
    }
}

Local Android Library Module 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'

}

回答1:


This problem is probably related to the version of Java that you are running. I had a similar problem and discovered that Java 8 was used for the build. When I changed to Java 7, this build problem was fixed.

In Android Studio go to

File -> Project Structure -> SDK Location

The JDK Location should be Java 1.7.x (Java 7)




回答2:


Yeah verify both machines have the same Java version, and indeed the same version of Android Studio. The only other thing I can think of is that maybe Stripe is using the build tools bundled with AS to build your apk, and the ones you have installed by default differ slightly and are missing something - see this post I made on a similar problem I had.



来源:https://stackoverflow.com/questions/33308153/gradle-dependency-causing-error-invalid-magic-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!