我已将我的项目迁移到使用Gradle(使用旧的Android项目结构)。 最近我将Android Studio升级到v0.2,这迫使我使用android gradle插件v0.5。 我可以使用我定义的任何风格来构建我的项目,无论是在调试/发布上。
使用以下方案让我出错:
建立成功
/Users/myuser/Project/src/com/namespace/project/views/SomeCustomView.java:60:错误:找不到符号 mSize = arr.getInt(R.styleable.SomeCustomView_some_custom_styleable,0);
Gradle现在抱怨我在attrs.xml中声明的每个自定义xml属性。 这让我疯了,因为我必须清洁和放弃我每次修改styles.xml重建我的项目
请帮帮我。
谢谢!
我的项目结构:
- Project
- . AndroidManifest.xml
- . assets/
- . build/
- . build.gradle
- . gen/
- . gradle/
- . gradle.properties
- . gradlew
- . libs (includes .jar files)
- . modules
- . . library_projectA
- . . library_projectB
- . out
- . project.properties
- . res
- . res_testenv
- . . values
- . . . strings.xml
- . res_prodenv
- . . values
- . . . strings.xml
- . settings.gradle
- . src/
- . . com/
- . . . namespace/
- . . . . android/
项目目录中的build.gradle:
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':modules:libprojectA')
compile project(':modules:libprojectB')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 17
}
signingConfigs {
release {
}
}
buildTypes {
debug {
runProguard false
}
alphaRelease {
runProguard false
zipAlign true
signingConfig signingConfigs.release
}
release {
runProguard true
proguardFile 'proguard-project.txt'
signingConfig signingConfigs.release
}
}
productFlavors {
testenv {}
prodenv {}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
aidl.srcDirs = ['src']
}
testenv {}
prodenv {}
}
android.sourceSets.testenv {
res.srcDirs = ['res_test']
}
android.sourceSets.prodenv {
res.srcDirs = ['res_prod']
}
}
if (project.hasProperty('storeFile') && project.hasProperty('storePassword') &&
project.hasProperty('keyAlias') && project.hasProperty('keyPassword')) {
android.signingConfigs.release.storeFile = file(storeFile)
android.signingConfigs.release.storePassword = storePassword
android.signingConfigs.release.keyAlias = keyAlias
android.signingConfigs.release.keyPassword = keyPassword
}
每个库项目的和build.gradle文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
附加堆栈跟踪:
org.gradle.api.tasks.TaskExecutionException:任务执行失败&#39 ;: compileTestenvDebug'。 at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46) 在org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35) 在org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter $ 1.run(CacheLockReleasingTaskExecuter.java:35) 在org.gradle.internal.Factories $ 1.create(Factories.java:22) 在org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179) 在org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232) 在org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142) at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83) at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33) 在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58) 在org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34) 在org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter $ 1.run(CacheLockAcquiringTaskExecuter.java:39) 在org.gradle.internal.Factories $ 1.create(Factories.java:22) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112) 在org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134) at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79) 在org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37) 在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57) 在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41) 在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51) 在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52) 在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42) 在org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48) at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89) 在org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) 在org.gradle.execution.DefaultBuildExecuter.access $ 200(DefaultBuildExecuter.java:23) 在org.gradle.execution.DefaultBuildExecuter $ 2.proceed(DefaultBuildExecuter.java:67) 在org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter $ 1.run(TaskCacheLockHandlingBuildExecuter.java:31) 在org.gradle.internal.Factories $ 1.create(Factories.java:22) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112) 在org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134) at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79) 在org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) 在org.gradle.execution.DefaultBuildExecuter.access $ 200(DefaultBuildExecuter.java:23) 在org.gradle.execution.DefaultBuildExecuter $ 2.proceed(DefaultBuildExecuter.java:67) 在org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61) 在org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54) 在org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166) 在org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113) 在org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81) at org.gradle.launcher.exec.InProcessBuildActionExecuter $ DefaultBuildController.run(InProcessBuildActionExecuter.java:64) 在org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33) 在org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35) at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26) 在org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50) 在org.gradle.api.internal.Actions $ RunnableActionAdapter.execute(Actions.java:171) 在org.gradle.launcher.cli.CommandLineActionFactory $ ParseAndBuildAction.execute(CommandLineActionFactory.java:201) 在org.gradle.launcher.cli.CommandLineActionFactory $ ParseAndBuildAction.execute(CommandLineActionFactory.java:174) 在org.gradle.launcher.cli.CommandLineActionFactory $ WithLogging.execute(CommandLineActionFactory.java:170) 在org.gradle.launcher.cli.CommandLineActionFactory $ WithLogging.execute(CommandLineActionFactory.java:139) 在org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33) 在org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22) 在org.gradle.launcher.Main.doAction(Main.java:48) 在org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45) 在org.gradle.launcher.Main.main(Main.java:39) 在org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50) 在org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32) 在org.gradle.launcher.GradleMain.main(GradleMain.java:26) 在org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:33) 在org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130) 在org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48) 引起:org.gradle.api.internal.tasks.compile.CompilationFailedException:编译失败;请参阅编译器错误输出以获取详细信 在org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:42) 在org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:33) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:95) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:48) 在org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:34) 在org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:29) 在org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:20) 在org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:33) 在org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:24) 在org.gradle.api.tasks.compile.Compile.compile(Compile.java:68) at org.gradle.api.internal.BeanDynamicObject $ MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216) 在org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122) 在org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147) 在org.gradle.api.tasks.compile.JavaCompile_Decorated.invokeMethod(未知来源) 在org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210) at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory $ StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199) 在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:526) 在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:509) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61) ......还有70多个
答案 0 :(得分:2)
我有一个理论,但我可能是错的。
看user
guide我没有
看到任何直接添加自定义源集的提及。这可能意味着
构建系统不会检测像testenv
这样的源集上的更改,除非它是a
味道或buildType的一部分。
我会尝试将您的环境定义为风味组。不确定 您的具体要求,但可能看起来像这样:
flavorGroups "environment", "flavors"
productFlavors {
testenv {
flavorGroup "environment"
}
prodenv {
flavorGroup "environment"
}
flavorA {
flavorGroup "flavors"
...
}
flavorB {
flavorGroup "flavors"
...
}
这假设您需要一个可以由这两者组成的构建,例如
app-flavor1-testenv-debug.apk
。只是一个想法,我没有测试过它。
另外,有一个建议,如果你让这个工作我会建议迁移到新的布局。这样,您可以依赖src/main/res
与src/testenv/res
和src/debug/res
合并的约定(如果它们存在),甚至不必在build.gradle
中提及它们。
答案 1 :(得分:2)
这已在0.5.4中修复,现在可以使用。