Java 尝试生成APK时,Gradle生成失败,出现意外错误
我已经编写了一段小代码,但每当我尝试构建apk时,都会出现以下错误:Java 尝试生成APK时,Gradle生成失败,出现意外错误,java,android,android-studio,Java,Android,Android Studio,我已经编写了一段小代码,但每当我尝试构建apk时,都会出现以下错误: 错误:任务“:app:transformClassesWithMultidexlistForDebug”的执行失败。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:使用带有参数的主类com.android.multidex.ClassReferenceListBuilder执行
错误:任务“:app:transformClassesWithMultidexlistForDebug”的执行失败。 com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:使用带有参数的主类com.android.multidex.ClassReferenceListBuilder执行java进程时出错{C:\Users\xxxx\Desktop\yyyyy\app\build\mediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\mediates\transforms\jarMerging\debug\jars\1\1f\combined.jar} 其中xxxx是我的用户名,yyyy是项目名称。
我已经尝试了在堆栈溢出上找到的所有可能的解决方案,但我意识到所有这些都是关于旧版本的 我有最新版本的Android Studio。我正在使用最新版本的Android SDK、构建工具、gradle、JDK 8.0和JRE 7。我还尝试了JRE 8
build.gradle(module app) :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "xxxx.yyyyy"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "Unreleased Demo Version"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled 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'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.1'
}
在you build.gradle/app中
defaultConfig {
....
//Add this line
multiDexEnabled true
}
dependencies {
....
//Add this line
compile 'com.android.support:multidex:1.0.0'
}
随着Android平台的不断发展,Android应用程序的规模也在不断扩大。当您的应用程序及其引用的库达到一定规模时,您会遇到生成错误,表明您的应用程序已达到Android应用程序生成架构的限值 修改模块级build.gradle文件以启用multidex并将multidex库添加为依赖项,如下所示:
在模块:App gradle文件夹中尝试此操作
multiDexEnabled 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'
}
当您的方法参考极限超过65536时,就会发生这种情况 第一步 您可以将以下内容添加到应用程序的build.gradle文件中
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
步骤2A
之后,您必须按照以下方式扩展应用程序类
public class MyApplication extends SomeOtherApplication {
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
或者,您可以按以下操作:
步骤2B
步骤3
最后更新清单文件,如下所示
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
...
您还没有共享任何代码和与您一起工作的依赖项,因此很难猜出确切的问题
但从您发布的错误来看,我认为您的程序已经超过了64K方法的限制
Apk文件以DEX的形式包含字节码文件,并且在单个DEX文件中有65536个方法的限制
因此,如果你的应用程序有超过64k的方法,你应该选择多个Dex文件
启用多个Dex,意味着应用程序构建过程将生成多个Dex文件
defaultConfig {
....
multiDexEnabled true
}
dependencies {
....
compile 'com.android.support:multidex:1.0.0'
}
我发现没有必要安装JDK和JRE(参考:android studio 2.3.2系统要求下的最新下载页面) 在programfiles/android studio中有一个名为“jre”的文件夹 所以我想我应该卸载JDK和JRE(与java相关的问题) 在此之后,我重新安装了android studio 现在它工作得很好。
(虽然对我有帮助,但我还没有做深入的研究)我已经尝试了所有可能的解决方案,包括这个。添加此go-to-FILE->Invidate Cahes/RestartTested后没有任何帮助。您可以帮助我使用Teamviewerok尝试删除编译“com.android.support:multidex:1.0.1”。我更新了答案错误:任务执行失败:app:TransformClasses Withmultidex ListFordebug”.com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:使用带有参数的主类com.android.multidex.ClassReferenceListBuilder执行java进程时出错{C:\xxxx\yyyyy\Desktop\VoterSearch\app\build\mediates\multi-dex\debug\componentClasses.jar C:\Users\xxxx\Desktop\yyyyy\app\build\mediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}**根据你的建议**我已经尝试了所有可能的解决方案,包括这个。这对我没有帮助。请显示你的
应用模块的build.gradle
文件。如果你还没有找到解决方案,还有一件事你可以尝试。转到磁盘中的项目文件夹,删除中间文件夹,然后再次构建你的项目,它会工作的好的,仍然是相同的问题libs
中有什么,哪些jar?没有jar文件。您可以解释步骤2 supoort库中提供了两个选项:第一个是您可以扩展普通的应用程序类,在attachBaseContext方法中,您可以设置MultiDex.install(这个)第二,你可以从MultiDexApplication本身扩展你的应用程序类,这样你就不需要在attachBaseContext方法上设置任何不工作的东西。现在它显示错误:任务执行失败“:app:TransformClasses WithMultidexListForDebug”。你使用的是32位系统还是64位?Windows 7 32位哪个操作系统?我有一个类似的问题问题
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
defaultConfig {
....
multiDexEnabled true
}
dependencies {
....
compile 'com.android.support:multidex:1.0.0'
}