当我运行gradle AssembleDebug
时,我收到错误消息,说已经添加了support-v4。我无法弄清楚为什么要加两次。完整的项目结构和错误日志如下所示。
我的目录结构如下(为清楚起见,删除了额外的目录)。
├── settings.gradle
├── project
│ ├── AndroidManifest.xml
│ ├── build.gradle
│ ├── res
│ └── src
└── vpi
├── AndroidManifest.xml
├── build.gradle
├── res
└── src
settings.gradle包含
include 'project'
include 'vpi'
project / build.gradle包含
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'org.jsoup:jsoup:1.7.2'
compile project(':vpi')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
vpi / build.gradle包含
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:18.0.+'
}
android {
compileSdkVersion 18
buildToolsVersion "18.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
当我运行命令gradle AssembleDebug
时,我得到了这个输出。
:project:preBuild UP-TO-DATE
:project:preDebugBuild UP-TO-DATE
:project:preReleaseBuild UP-TO-DATE
:vpi:compileLint
:vpi:copyReleaseLint UP-TO-DATE
:vpi:mergeReleaseProguardFiles UP-TO-DATE
:vpi:packageReleaseAidl UP-TO-DATE
:vpi:preBuild UP-TO-DATE
:vpi:preReleaseBuild UP-TO-DATE
:vpi:prepareReleaseDependencies
:vpi:compileReleaseAidl UP-TO-DATE
:vpi:compileReleaseRenderscript UP-TO-DATE
:vpi:generateReleaseBuildConfig UP-TO-DATE
:vpi:mergeReleaseAssets UP-TO-DATE
:vpi:mergeReleaseResources UP-TO-DATE
:vpi:processReleaseManifest UP-TO-DATE
:vpi:processReleaseResources UP-TO-DATE
:vpi:generateReleaseSources UP-TO-DATE
:vpi:compileRelease
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:vpi:processReleaseJavaRes UP-TO-DATE
:vpi:packageReleaseJar UP-TO-DATE
:vpi:packageReleaseLocalJar UP-TO-DATE
:vpi:packageReleaseRenderscript UP-TO-DATE
:vpi:packageReleaseResources UP-TO-DATE
:vpi:bundleRelease UP-TO-DATE
:project:prepareAndroidAppVpiUnspecifiedLibrary UP-TO-DATE
:project:prepareComActionbarsherlockActionbarsherlock440Library UP-TO-DATE
:project:prepareDebugDependencies
:project:compileDebugAidl UP-TO-DATE
:project:compileDebugRenderscript UP-TO-DATE
:project:generateDebugBuildConfig UP-TO-DATE
:project:mergeDebugAssets UP-TO-DATE
:project:mergeDebugResources UP-TO-DATE
:project:processDebugManifest UP-TO-DATE
:project:processDebugResources UP-TO-DATE
:project:generateDebugSources UP-TO-DATE
:project:compileDebug UP-TO-DATE
:project:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
at com.android.dx.command.dexer.Main.processClass(Main.java:490)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
1 error; aborting
:project:dexDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':project:dexDebug'.
> Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/18.1.0/dx --dex --output /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/libs/project-debug.dex /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/classes/debug /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/dependency-cache/debug /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/libs/GoogleAdMobAdsSdk-6.4.1.jar /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/exploded-bundles/AndroidAppVpiUnspecified.aar/libs/android-support-v4.jar /Users/yasith/.gradle/caches/artifacts-26/filestore/org.jsoup/jsoup/1.7.2/jar/d7e275ba05aa380ca254f72d0c0ffebaedc3adcf/jsoup-1.7.2.jar /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/libs/libGoogleAnalyticsV2.jar /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/exploded-bundles/AndroidAppVpiUnspecified.aar/classes.jar /Users/yasith/Projects/Mississauga-Busses/AndroidApp/project/build/exploded-bundles/ComActionbarsherlockActionbarsherlock440.aar/classes.jar /Applications/Android Studio.app/sdk/extras/android/m2repository/com/android/support/support-v4/18.0.0/support-v4-18.0.0.jar
Error Code:
1
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
at com.android.dx.command.dexer.Main.processClass(Main.java:490)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:459)
at com.android.dx.command.dexer.Main.access$400(Main.java:67)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:398)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
at com.android.dx.command.dexer.Main.processOne(Main.java:422)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:333)
at com.android.dx.command.dexer.Main.run(Main.java:209)
at com.android.dx.command.dexer.Main.main(Main.java:174)
at com.android.dx.command.Main.main(Main.java:91)
1 error; aborting
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 25.296 secs
答案 0 :(得分:1)
将我的project / build.gradle文件更改为如下所示。 (删除了compile 'com.android.support:support-v4:18.0.0'
位)。
dependencies {
compile project(':vpi')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'org.jsoup:jsoup:1.7.2'
compile fileTree(dir: 'libs', include: '*.jar')
}
这似乎使gradle DebugAssemble
起作用。我确实也运行gradle clean DebugAssemble
,不确定这是否与此工作有关。
还必须将local.properties
文件添加到包含。
sdk.dir=/Applications/Android Studio.app/sdk
执行此操作后,从Android Studio导入settings.gradle文件。