duplicate files during packaging of apk

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即可以成功编译。

OSChina Android APP 源码在Android Studio中运行

APP build.gradle 配置文件内容为:

 

apply plugin: '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')
}
posted @ 2015-07-07 17:54  netcorner  阅读(2191)  评论(0编辑  收藏  举报