我是Android Studio的新手,因为我一直使用Eclipse。现在我尝试将两个库(MPChartLib和datetimepicker-library)导入为jar。
我做的步骤:
1.创建一个名为libraries的文件夹
2.将罐子拖放到文件夹
中
3.右键单击它们 - >添加到图书馆(类似的东西)
(正如我在一些教程中看到的那样)
系统识别这些罐子,我可以使用它们。但是当我想运行该项目时,我收到以下错误:
Information:Gradle tasks [:app:assembleDebug]
:app:preBuild
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72100Library UP-TO-DATE
:app:prepareComAndroidSupportGridlayoutV72100Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72100Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72100Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42100Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
Error:duplicate files during packaging of APK
C:\Users\Markus\Documents\AndroidStudiosWORKSPACE\TestProject\app\build\outputs\apk\app-debug- unaligned.apk
Path in archive: res/values/colors.xml
Origin 1: C:\Users\Markus\Documents\AndroidStudiosWORKSPACE\TestProject\app\libraries\datetimepicker-library.jar
Origin 2: C:\Users\Markus\Documents\AndroidStudiosWORKSPACE\TestProject\app\libraries\MPChartLib.jar
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'res/values/colors.xml'
}
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK res/values/colors.xml
File 1: C:\Users\Markus\Documents\AndroidStudiosWORKSPACE\TestProject\app\libraries\datetimepicker-library.jar
File 2: C:\Users\Markus\Documents\AndroidStudiosWORKSPACE\TestProject\app\libraries\datetimepicker-library.jar
这不是我第一次收到此错误,因此我已经搜索了几个小时的解决方案 - 徒劳无功。
以下是我的build.gradle,其中我已经排除了许多文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "20.0.0"
packagingOptions {
exclude 'AndroidManifest.xml'
exclude 'bin/AndroidManifest.xml'
exclude 'bin/R.txt'
exclude 'bin/jarlist.cache'
exclude 'build.gradle'
exclude 'proguard-project.txt'
exclude 'project.properties'
}
defaultConfig {
applicationId "com.nomax.gymdiary"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:gridlayout-v7:21.0.0'
compile 'com.android.support:mediarouter-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile files('libraries/datetimepicker-library.jar')
compile files('libraries/MPChartLib.jar')
}
我确定我不必排除那些重要文件(可以在最新错误中看到,我也必须排除res / values / colors.xml)
来自奥地利的问候!
PS:我已经将Eclipse中的libs从Eclipse项目导出到了jar文件中。这可能是问题吗?