Java com.android.build.transform.api.TransformException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32807587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:08:07  来源:igfitidea点击:

com.android.build.transform.api.TransformException

javaandroidgradlegoogle-play-servicesgoogle-signin

提问by saeed shahini

I am trying to integrate Google sign in, in my app, I added these libraries:

我正在尝试集成 Google 登录,在我的应用程序中,我添加了这些库:

compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'

Also add this to project build gradle:

还要将此添加到项目构建 gradle 中:

classpath 'com.google.gms:google-services:1.4.0-beta3'

Also add plugin to app build gradle:

还要向应用程序构建 gradle 添加插件:

apply plugin: 'com.google.gms.google-services'

then add required permissions but when I try to run my app, received this error:

然后添加所需的权限,但是当我尝试运行我的应用程序时,收到此错误:

    Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
    com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: 
    org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0\bin\java.exe'' finished with non-zero exit value 2

采纳答案by JuliusScript

Try adding multiDexEnabled trueto your app build.gradlefile.

尝试添加multiDexEnabled true到您的应用build.gradle文件中。

 defaultConfig {
    multiDexEnabled true
}

EDIT:

编辑:

Try Steve's answerfirst. In case it happens frequently or first step didn't help multiDexEnabledmight help. For those who love to dig deeper here is couple similar issues (with more answers):

首先尝试史蒂夫的答案。如果它经常发生或第一步没有帮助multiDexEnabled可能会有所帮助。对于那些喜欢深入挖掘的人来说,这里有几个类似的问题(有更多答案):

:app:dexDebug ExecException finished with non-zero exit value 2

:app:dexDebug ExecException 以非零退出值 2 结束

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException

错误:任务 ':app:dexDebug' 执行失败。com.android.ide.common.process.ProcessException

回答by Steve Ganem

I just had to Clean my project and then it built successfully afterwards.

我只需要清理我的项目,然后它就成功构建了。

回答by A.Grandt

Another thing to watch for, is that you don't use

另一件需要注意的事情是你不使用

compile 'com.google.android.gms:play-services:8.3.0'

That will import ALL the play services, and it'll only take little more than a hello world to exceed the 65535 method limit of a single dex APK.

这将导入所有播放服务,并且只需要一个 hello world 就可以超过单个 dex APK 的 65535 方法限制。

Always specify only the services you need, for instance:

始终只指定您需要的服务,例如:

compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-plus:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'

回答by goonerDroid

If you are using the latest gradle version ie classpath 'com.android.tools.build:gradle:1.5.0' and classpath 'com.google.gms:google-services:1.4.0-beta3', then try updating the latest support respository from the SDK manager and rebuild the entire project.

如果您使用的是最新的 gradle 版本 ie classpath 'com.android.tools.build:gradle:1.5.0' and classpath 'com.google.gms:google-services:1.4.0-beta3',请尝试从 SDK 管理器更新最新的支持库并重建整个项目。

回答by raul

I also faced similar issue in Android Studio 1.5.1 and gradle 1.5.0. I just have to remove unwanted libraries from dependencies which may be automatically added in my app's build.gradle file. One was : compile 'com.google.android.gms:play-services:8.4.0'. So for best practices try to only include specific play services library like for ads include only

我在 Android Studio 1.5.1 和 gradle 1.5.0 中也遇到过类似的问题。我只需要从依赖项中删除不需要的库,这些库可能会自动添加到我的应用程序的 build.gradle 文件中。一个是:编译'com.google.android.gms:play-services:8.4.0'。因此,对于最佳实践,请尝试仅包含特定的播放服务库,例如仅包含广告

dependencies {
    compile 'com.google.android.gms:play-services-ads:8.4.0'
}

Although

虽然

defaultConfig {
    multiDexEnabled true
}

this will also solve the issue, but provides with a lot of Notes in gradle console, making it confusing to find the other real issues during build

这也将解决问题,但在 gradle 控制台中提供了大量注释,使得在构建过程中发现其他实际问题变得混乱

回答by kcNeko

I'm using AS 1.5.1 and encountered the same problem. But just cleaning the project just wont do, so I tried something.

我使用的是 AS 1.5.1 并遇到了同样的问题。但是仅仅清理项目是不行的,所以我尝试了一些东西。

  • clean project
  • restart AS
  • Sync Project
  • 清洁工程
  • 重启 AS
  • 同步项目

This worked with me, so I hope this helps.

这对我有用,所以我希望这会有所帮助。

回答by Maurice Gavin

This error began appearing for me when I added some new methods to my project. I knew that I was nowhere near the 65k method limit and did not want to enable multiDex support for my project if I could help it.

当我向我的项目添加一些新方法时,这个错误开始出现。我知道我离 65k 方法的限制还差得很远,如果我能帮上忙,我不想为我的项目启用 multiDex 支持。

I resolved it by increasing the memory available to the :app:transformClassesForDexForDebugtask. I did this by specifying javaMaxHeapSizein gradle.build.

我通过增加:app:transformClassesForDexForDebug任务可用的内存来解决它。我通过指定这样做javaMaxHeapSizegradle.build

gradle.build

gradle.build

android {
    ...
    dexOptions {
        javaMaxHeapSize "4g" //specify the heap size for the dex process
    }
}

I tried this after having had no success with other common solutions to this problem:

在使用其他常见解决方案未能成功解决此问题后,我尝试了此方法:

  • Running a project clean
  • Manually deleting the /app/buildand /builddirectories from my project
  • Invalidating Gradle Cache and restarting Android Studio
  • 运行项目 clean
  • 从我的项目中手动删除/app/build/build目录
  • 使 Gradle 缓存无效并重新启动 Android Studio

Error

错误

Error:Execution failed for task > ':app:transformClassesWithDexForDebug'. com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

错误:任务 > ':app:transformClassesWithDexForDebug' 执行失败。com.android.build.api.transform.TransformException:com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'命令'/Library/Java/JavaVirtualMachines/jdk1.8.0_45。 jdk/Contents/Home/bin/java'' 以非零退出值 1 结束

Note: increasing the memory available to the DEX task can cause performance problems on systems with lower memory - link.

注意:增加 DEX 任务可用的内存可能会导致内存链接较低的系统出现性能问题。

回答by David Hackro

you can see the documentation of Android

你可以看到Android的文档

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

Manifest.xml

清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

回答by lxknvlk

I had same problem when i rolled back to old version via git, and that version had previous .jar library of one 3rd party api, and for some reason turned out that both jar of the same sdk, just different versions were in /libs folder.

当我通过 git 回滚到旧版本时,我遇到了同样的问题,并且该版本具有一个 3rd 方 api 的以前的 .jar 库,并且由于某种原因,结果是同一 sdk 的两个 jar,只是不同的版本在 /libs 文件夹中.

回答by Adexe Rivera

If you need add this reference for cordova plugin add next line in your plugin.xml file.

如果您需要为cordova 插件添加此参考,请在您的plugin.xml 文件中添加下一行。

<framework src="com.android.support:support-v4:+" />