本文共 1985 字,大约阅读时间需要 6 分钟。
OSChina Android APP 导入到Android Studio中不能运行,发现一小插曲。
主要实现了开源中国社区 OSC Android 客户端项目源码通过Gradle方式编译 在 Android Studio运行并模拟。
出现这个报错:
Error:duplicate files during packaging of APK /Users/lixiphp/AndroidStudioProjects/oschina-android/app/build/outputs/apk/app-debug-unaligned.apk
Error:Execution failed for task ‘:app:packageDebug’.
> Duplicate files copied in APK META-INF/NOTICE.txt
File 1: /Users/lixiphp/AndroidStudioProjects/oschina-android/app/libs/commons-httpclient-3.1.jar
File 2: /Users/lixiphp/AndroidStudioProjects/oschina-android/app/libs/commons-httpclient-3.1.jar
这个APP运行的环境是在SDK API 15,如果你改为19或者更高是会报错的。
JDK=1.6
target=android-15
在gradle配置文件加入:
android { 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' } }
在运行一次APP即可以成功编译。
APP build.gradle 配置文件内容为:
'android'android { compileSdkVersion 15 buildToolsVersion "20.0.0" defaultConfig { applicationId "net.oschina.app" minSdkVersion 9 targetSdkVersion 19 } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } android { 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 files('libs/Android_SDK_v1.2_Fix.jar') compile files('libs/commons-httpclient-3.1.jar') compile files('libs/core-2.3.0.jar') compile files('libs/httpmime-4.1.3.jar') compile files('libs/libammsdk.jar')
}
本文转自 netcorner 博客园博客,原文链接:http://www.cnblogs.com/netcorner/p/4627754.html ,如需转载请自行联系原作者