导致错误的Gradle依赖关系“无效幻数” [英] Gradle dependency causing error "Invalid Magic Number"

查看:183
本文介绍了导致错误的Gradle依赖关系“无效幻数”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitHub上有一个项目,我在家里的办公室工作。大约2个月它在两台机器上工作正常。然后两周前,它停止在我的家用PC上运行,但在我的工作PC上仍然正常工作



这是我得到的错误:


:app:shrinkDebugMultiDexComponents FAILED

失败:构建失败,出现异常。


  • 出错:
    任务':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 给我错误的软件包是第三方库你可以在这里找到

  compile'c​​om.stripe:stripe- android:+'

我已经注释掉了所有有关 stripe 和应用程序运行完全正常,所以我知道这与我如何处理该包有关。

不幸的是,我不记得我已经做了什么让这个停止工作。我认为在这之前的一周里我升级了Android Studio,并花费了大量的时间来处理 ProGuard 配置。



我尝试过的方法:
$ b


  • 工作在 master 分支中没有 ProGuard 更改

  • 卸载和重新安装Android Studio
  • 重新克隆git repo
  • 安装API 17(eclipse的stripe需要这个。不是Studio,但是我给了它一个镜头)。

  • 联系分条客户支持,但他们不知道。 这个堆栈溢出帖子。但是,没有任何Mac电脑已经触及该项目,也没有我个人压缩任何与 stripe 相关的任何内容

  • 从这里开始,将幻数从Hex转换为ASCII。结果是 Q` ,我不认识它。



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

编辑



我在调试 BuildType。这些是我的3个gradle文件。第一个用于整个Project,第二个用于应用程序模块,第三个用于本地android库Module。



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

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

Android应用程序模块 build.gradle

  buildscript {
存储库{
maven {url'https://maven.fabric.io/public'}
}

依赖项{
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
buildToolsVersion22.0.1

defaultConfig {
applicationIdcom.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'布尔','enableCrashlytics','tru e'
}
debug {
buildConfigField'布尔','enableCrashlytics','false'
}
adhoc {
可调试真
signedConfig signingConfigs.debug
buildConfigField'Boolean','enableCrashlytics','true'
}
}
packagingOptions {
exclude'META-INF / DEPENDENCIES.txt'
排除'META-INF / LICENSE.txt'
排除'META-INF / NOTICE.txt'
排除'META-INF / NOTICE'
排除'META-INF /许可'
排除'META-INF /相关性'
排除'META-INF / notice.txt'
排除'META-INF / license.txt'
排除'META- INF / dependencies.txt'
exclude'META-INF / LGPL2.1'
}
}
依赖关系{
编译项目(':localLibrary')
编译'com.facebook.android:facebook-and roid-sdk:3.21.1'
compile'c​​ommons-io:commons-io:2.4'
compile'c​​om.github.bumptech.glide:glide:3.6.1'
compile' com.android.support:support-v4:22.0.1'
compile'c​​om.google.android.gms:play-services-identity:8.1.0'
compile'c​​om.google.android。 gms:play-services-plus:8.1.0'
compile'c​​om.google.android.gms:play-services-maps:8.1.0'
compile'c​​om.android.support:multidex: 1.0.1'
compile'io.card:android-sdk:5.0.1'
compile'c​​om.stripe:stripe-android:''
compile('com.crashlytics.sdk .android:crashlytics:2.5.2@aar'){
transitive = true;




本地Android库模块 build.gradle

  apply plugin:'com.android.library' 

android {
compileSdkVersion 22
buildToolsVersion22.0.1

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled = true
}

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

依赖关系{
编译'com.android.support:support-v4:22.1.0'
编译'com.google.code.gson:gson:2.2.2'
编译'com.android.support:multidex:1.0.0'
编译组:'org.apache。 httpcomponents',名称:'httpmime',版本:'4.3.5'
编译组:'org.apache.httpcomponen ts',name:'httpclient-android',版本:'4.3.5'

}


解决方案

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



在Android Studio中转到

 文件 - >项目结构 - > SDK位置

JDK位置应该是Java 1.7.x(Java 7)

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'

}

解决方案

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)

这篇关于导致错误的Gradle依赖关系“无效幻数”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆