添加支持库报错如何解决
How to solve the error while adding a support library
我第一次尝试为通知项目添加支持库。但是遇到了一些错误
> 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
> 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with
> non-zero exit value 2
不知道怎么解决,望大神指点。
我的构建 Gradel
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.union.noti"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile files('libs/android-support-v4.jar')
compile 'com.android.support:multidex:1.0.1'
}
我现在正在添加 multidex 时出错
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/LayoutRes.class
尝试将其放入 android 部分的 Build.gradle(Module:app)
defaultConfig {
multiDexEnabled true
}
如果无法正常工作,请尝试重新启动 android 工作室。
希望对您有所帮助。
在您的根 Gradle 文件中执行此操作
defaultConfig {
applicationId "com.xxxxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
您需要在您的 Gradle 文件 中添加 Multidexing 就像在 Image[= 中看到的那样23=].. 请用突出显示的部分
更新您的gardle
检查突出显示的部分,像这样粘贴
与其他答案相反,您不需要启用 multidex。
您正在编译 v4 库两次...删除 compile files
行,因为 compile fileTree
已经处理了它,它表示要编译 lib 目录中的所有 jar 文件。因此,您不需要添加额外的行,除非 jar 文件位于 lib 目录之外。
compile fileTree(include: ['*.jar'], dir: 'libs')
//...
compile files('libs/android-support-v4.jar')
无论如何,你为什么不用 Gradle 编译 v4 库?
compile "com.android.support:support-v4:23.0.1"
为什么要将 android-support-v4.jar 放在 libs 文件夹中。如果你想像这样使用 android-support-v4.jar 库 uee :
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:multidex:1.0.1'
}
在您的项目支持库和设计库或 appcompat 库的某些地方存在冲突。因为支持库中也有 appcompat 库。像这样使用可能对你有帮助。如果不成功请告诉我。
我第一次尝试为通知项目添加支持库。但是遇到了一些错误
> 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
> 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with
> non-zero exit value 2
不知道怎么解决,望大神指点。 我的构建 Gradel
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.union.noti"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile files('libs/android-support-v4.jar')
compile 'com.android.support:multidex:1.0.1'
}
我现在正在添加 multidex 时出错
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/LayoutRes.class
尝试将其放入 android 部分的 Build.gradle(Module:app)
defaultConfig {
multiDexEnabled true
}
如果无法正常工作,请尝试重新启动 android 工作室。
希望对您有所帮助。
在您的根 Gradle 文件中执行此操作
defaultConfig {
applicationId "com.xxxxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
您需要在您的 Gradle 文件 中添加 Multidexing 就像在 Image[= 中看到的那样23=].. 请用突出显示的部分
更新您的gardle检查突出显示的部分,像这样粘贴
与其他答案相反,您不需要启用 multidex。
您正在编译 v4 库两次...删除 compile files
行,因为 compile fileTree
已经处理了它,它表示要编译 lib 目录中的所有 jar 文件。因此,您不需要添加额外的行,除非 jar 文件位于 lib 目录之外。
compile fileTree(include: ['*.jar'], dir: 'libs')
//...
compile files('libs/android-support-v4.jar')
无论如何,你为什么不用 Gradle 编译 v4 库?
compile "com.android.support:support-v4:23.0.1"
为什么要将 android-support-v4.jar 放在 libs 文件夹中。如果你想像这样使用 android-support-v4.jar 库 uee :
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:multidex:1.0.1'
}
在您的项目支持库和设计库或 appcompat 库的某些地方存在冲突。因为支持库中也有 appcompat 库。像这样使用可能对你有帮助。如果不成功请告诉我。