2017-08-14 113 views
0

我试图将我的AS升级到最新的beta2,并遇到以下问题,我的applib模块。升级到Android 3.0 beta 2后无法解析库项目

在我appbuild.gradle我有2种口味

flavorDimensions "default" 
     productFlavors { 
      stage { 
      applicationId "com.mycompany.hello.stage" 
      resValue "string", "app_name", "Stage" 
      } 
      production { 
      applicationId "com.mycompany.hello.stage.production" 
      resValue "string", "app_name", "Live" 
      } 
     } 

我指定的应用程序将如下只跟特定类型的我lib

stageCompile project(path: ':lib', configuration: 'debug') 
productionCompile project(path: ':lib', configuration: 'release') 

libbuild.gradle文件我只有建立类型和没有风味块

publishNonDefault true 
buildTypes { 
    debug { 
     versionNameSuffix ".debug" 
    } 
    release { 
     versionNameSuffix ".release" 
     minifyEnabled true 
    } 
} 

以上代码是我的最佳知识,app将取决于构建变体并与lib的特定构建变体进行交谈。它工作完美,直到我升级到AS 3.0。

这里是gradle错误消息......我不确定这是否是由我的两个gradle文件中的flavorDimensions不匹配造成的。

Error:Could not determine the dependencies of task ':app:compileStageDebugAidl'. 
> Could not resolve all task dependencies for configuration ':app:stageDebugCompileClasspath'. 
> Could not resolve project :lib. 
Required by project :app 
> Project :app declares a dependency from configuration 'stageCompile' to configuration 'debug' which is not declared in the descriptor for project :lib. 

回答

0

所以我花了几个小时,我的迁移项目相匹配的迁移指南中提供我的Android Studio

我最终会做以下修改达到我想要的:

app变种productionRelease应该调用librelease

app变种stageDebug应该调用libdebug

应用的build.gradle文件

flavorDimensions "default" //add this line for flavorDimensions 
productFlavors { 
    stage { 
     ... 
    } 

    production { 
     ... 
    } 
} 
implementation project(':lib') 

在我的lib的build.gradle我保持不变

publishNonDefault true 
buildTypes { 
    debug { 
     versionNameSuffix ".debug" 
    } 
    release { 
     versionNameSuffix ".release" 
     minifyEnabled true 
    } 
} 

,唯一的缺点我这里是忽略某些变种我不想实现productionRelease(应用程序)+释放(LIB)和stageDebug(应用程序)+调试(lib)组合。

//以这种方式,我将只有productionReleasestageDebug变体留在AS面板中。

在应用的build.gradle

variantFilter { variant -> 
    def names = variant.flavors*.name 
    if (names.contains("stage") && variant.buildType.name == "release") { 
     variant.ignore = true 
    } 
    if (names.contains("production") && variant.buildType.name == "debug") { 
     variant.ignore = true 
    } 
} 

当我切换打造我app变种,它也将我切换到lib相应的构建类型。

我还不确定这是否是最佳做法。如果你们找到了更好的方法来做到这一点。请让我知道。

相关问题