gpt4 book ai didi

Android Gradle 构建失败 - Java 以非零退出 2 完成

转载 作者:行者123 更新时间:2023-11-29 19:47:52 24 4
gpt4 key购买 nike

所以我正在尝试使用 Android Studio 开发一个应用程序。一切正常。然后我想像几分钟前一样在虚拟设备上运行我的应用程序,但它无法同步 Gradle 构建:

Error:Failed to resolve: com.google.android.gms:play-services-measurement:9.0.0 Install Repository and sync project
Open File
Show in Project Structure dialog

这是我的 Gradle 项目:

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这是我的模块 Gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.example.stefan.myapplication"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
exclude 'META-INF/ECLIPSE_.RSA'
exclude 'META-INF/ECLIPSE_.SF'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile project(':org.eclipse.paho.android.service-1.0.2')
compile project(':org.eclipse.paho.client.mqttv3-1.0.2')

compile project(':android-beacon-library-2.8.1')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services:9.0.0'
compile 'com.android.support:support-v4:23.4.0'
}
apply plugin: 'com.google.gms.google-services'

所以我研究并尝试了这个:https://stackoverflow.com/a/37312564/6256209并将 com.google.gms:google-services:2.0.0-alpha6 更改为 com.google.gms:google-services:3.0.0

之后,我的 Gradle Build 将在 5 秒左右的时间内正常同步。

但是如果我想在虚拟设备上运行它会失败。它给了我 4 个错误:

Error:java.lang.RuntimeException: com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Users\Stefan\JEE\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2

所有这些都以非零退出值结束。

所以我找到了这个:Java finished with non-zero exit value 2 - Android Gradle

然后我尝试将 multiDexEnabled 设置为 true 并检查是否包含不必要的库。我还清理并重建了应用程序,但没有任何效果。

我非常感谢任何形式的帮助和建议

最佳答案

首先你应该这样称呼

dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'

}

The Android plugin for Gradle available in Android SDK Build Tools 21.1 and higher supports multidex as part of your build configuration. Make sure you update the Android SDK Build Tools tools and the Android Support Repository to the latest version using the SDK Manager before attempting to configure your app for multidex.

然后添加multiDexEnabled true

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
...
minSdkVersion 14
targetSdkVersion 23
...

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

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

最后 Clean-Rebuild-Sync-Run

关于Android Gradle 构建失败 - Java 以非零退出 2 完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37413542/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com