我正在使用 gradle 构建我的 android 项目并遇到了一个相当奇怪的问题。
当我第一次运行“gradlew build”时,由于 proguard 找不到引用的类,构建将中断。但是,当我再次运行“gradlew build”时,构建可以成功完成。
D:\project\abs-demo>gradlew clean
D:\project\abs-demo>gradlew build // first time, fail
D:\project\abs-demo>gradlew build // second time, succeed
报错信息如下:
Warning: com.actionbarsherlock.sample.demos.ActionItems: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning: com.actionbarsherlock.sample.demos.ActionModes: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning: com.actionbarsherlock.sample.demos.ActionModes$AnActionModeOfEpicProportions: can't find superclass or interface com.actionbarsherlock.view.ActionMode$Callback
Warning: com.actionbarsherlock.sample.demos.ActionModesNoActionBar: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning: com.actionbarsherlock.sample.demos.ActionModesNoActionBar$AnActionModeOfEpicProportions: can't find superclass or interface com.actionbarsherlock.view.ActionMode$Callback
Warning: com.actionbarsherlock.sample.demos.ActionProviders: can't find superclass or interface com.actionbarsherlock.app.SherlockActivity
Warning: com.actionbarsherlock.sample.demos.ActionProviders$SettingsActionProvider: can't find superclass or interface com.actionbarsherlock.view.ActionProvider
....
我正在使用 gradle 0.7。还有我的 build.gralde:
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile "com.android.support:support-v4:18.0.+"
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
}
android {
compileSdkVersion 19
buildToolsVersion "18.0.0"
buildTypes {
release {
runProguard true
proguardFile getDefaultProguardFile('proguard-android.txt')
proguardFile 'proguard-project.txt'
}
}
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')
}
}
我上传了my project here .
我做错了什么吗?还是gradle的bug?
最佳答案
这是 Android Gradle 插件版本 0.7.0 和 0.7.1 中的一个问题:issue 63944和 issue 64039 .
关于android - Proguard第一次运行 "gradlew build"时找不到引用的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20740196/