我的Android项目包含3个build.gradle
个文件:
项目build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
// mavenLocal()
jcenter()
}
dependencies {
// classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
allprojects {
repositories {
jcenter()
}
}
MYAPP build.gradle
apply plugin: 'com.android.library'
android {
dexOptions {
preDexLibraries = false
}
compileSdkVersion 17
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile files('libs/CWAC-AdapterWrapper.jar')
}
和Facebook SDK:
apply plugin: 'com.android.library'
android {
dexOptions {
preDexLibraries = false
}
compileSdkVersion 8
buildToolsVersion "21.1.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
} }
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
我能够构建项目但不能运行它。例外是:
> Note: Some input files use or override a deprecated API. Note:
> Recompile with -Xlint:deprecation for details. Note: Some input files
> use unchecked or unsafe operations. Note: Recompile with
> -Xlint:unchecked for details. :awakenings:dexDebug UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already
> added: Ledu/mit/mobile/android/imagecache/DiskCache$1; at
> com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
> at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at
> com.android.dx.command.dexer.Main.processClass(Main.java:732) at
> com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) at
> com.android.dx.command.dexer.Main.access$300(Main.java:82) at
> com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
> at
> com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
> at
> com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
> at
> com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
> at com.android.dx.command.dexer.Main.processOne(Main.java:632) at
> com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) at
> com.android.dx.command.dexer.Main.runMonoDex(Main.java:279) at
> com.android.dx.command.dexer.Main.run(Main.java:245) at
> com.android.dx.command.dexer.Main.main(Main.java:214) at
> com.android.dx.command.Main.main(Main.java:106) UNEXPECTED TOP-LEVEL
> EXCEPTION: java.lang.IllegalArgumentException: already added:
> Lcom/facebook/AccessToken$1; at
> com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
> at com.android.dx.dex.file.DexFile.add(DexFile.java:161) at
> com.android.dx.command.dexer.Main.processClass(Main.java:732) at
> com.android.dx.command.dexer.Main.processFileBytes(Main.java:673) at
> com.android.dx.command.dexer.Main.access$300(Main.java:82) at
> com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
> at
> com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
> at
> com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
> at
> com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
> at com.android.dx.command.dexer.Main.processOne(Main.java:632) at
> com.android.dx.command.dexer.Main.processAllFiles(Main.java:510) at
> com.android.dx.command.dexer.Main.runMonoDex(Main.java:279) at
> com.android.dx.command.dexer.Main.run(Main.java:245) at
> com.android.dx.command.dexer.Main.main(Main.java:214) at
> com.android.dx.command.Main.main(Main.java:106) 2 errors; aborting
> Error:Execution failed for task ':awakenings:dexDebug'.
> > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command
> 'C:\Program Files\Java\jdk1.8.0_20\bin\java.exe'' finished with
> non-zero exit value 1
有些东西是重复但我不知道是什么。你有什么想法没有运行吗?
问题似乎是前两个模块在我的DEX中包含TWICE
settings.gradle include':androidImageCachemaster'include ':facebookSDK'
然后
¸¸dependencies{ 编译项目(':facebookSDK') 编译项目(':androidImageCachemaster')
这是屏幕截图
答案 0 :(得分:0)
文件中是否有一个名为DiskCache的函数: com.android.dx.command.Main.main
这似乎与facebook sdk中的功能相冲突。尝试重命名您的功能
已更新-------
请在build.grade中尝试此操作。这应该编译依赖项,但将其从最终构建中排除:
android {
compileSdkVersion x
buildToolsVersion "x"
packagingOptions {
exclude 'support-v4'
}
...
}
答案 1 :(得分:0)
build.gradle
:// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.3'
}
}
allprojects {
repositories {
jcenter()
}
}
在此处下载Facebook for Android Gradle库:https://developers.facebook.com/docs/android。
将其作为模块导入您自己的项目。
它会将其添加为模块。因此,请添加到您自己的build.gradle
,compile project(':facebook-android-sdk-4.0.1')
作为依赖项。
app/build.gradle
在此处下载Facebook for Android Gradle库:https://developers.facebook.com/docs/android。
apply plugin: 'com.android.application' // changed to application
android {
compileSdkVersion 22 // <-- updated
buildToolsVersion "22.0.1" // <-- updated
defaultConfig {
minSdkVersion 11 // <-- updated
targetSdkVersion 22 // <-- updated
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.0.0' // <-- updated
compile files('libs/CWAC-AdapterWrapper.jar')
// compile project(':facebook-android-sdk-4.0.1') // <-- something like this
}