Android Wear应用程序打包失败与口味

我有一个包含磨损应用程序的应用程序。 所有的工作都很好,用一个真实的设备进行testing。 我可以创build释放apk包里面的穿apk。 但是,只有在我的应用程序只有一个味道。

我想用不同的applicationId来维护两个版本的应用程序,但是虽然这个编译没有错误,但是在这种情况下,两个释放apks(每个flavor的其中之一)不会相应的穿戴apks。

这是移动应用程序build.gradle的相关部分:

productFlavors { Trial { applicationId "com.example.myapp.trial" versionName "3.0.1" versionCode 301 } Full { applicationId "com.example.myapp" versionName "3.0.1" versionCode 301 } } } dependencies { compile 'com.google.android.gms:play-services:6.1.+@aar' wearApp project(':myWearApp') } 

这是对应的应用程序build.gradle:

 productFlavors { Trial { applicationId "com.example.myapp.trial" versionName "3.0.1" versionCode 301 } Full { applicationId "com.example.myapp" versionName "3.0.1" versionCode 301 } } } dependencies { compile 'com.google.android.support:wearable:1.0.0' compile 'com.google.android.gms:play-services-wearable:6.1.71' } 

任何帮助将受到欢迎。 谢谢。

Solutions Collecting From Web of "Android Wear应用程序打包失败与口味"

感谢斯科特给我的线索,这是完整的解决scheme:

1.)味道必须是小写的

2.)依赖configuration必须包含flavor 释放

3.)在Wear应用程序构buildgradle中,在android {}下,我们必须包含publishNonDefault true

所以对于移动应用build.gradle:

 android { ...... productFlavors { trial { applicationId "com.sample.myapp.trial" versionName "3.0.1" versionCode 301 } full { applicationId "com.sample.myapp" versionName "3.0.1" versionCode 301 } } } dependencies { trialWearApp project(path: ':myWearApp', configuration: 'trialRelease') fullWearApp project(path: ':myWearApp', configuration: 'fullRelease') } 

并为穿app build.gradle:

 android { publishNonDefault true ...... productFlavors { trial { applicationId "com.sample.myapp.trial" versionName "3.0.1" versionCode 301 } full { applicationId "com.sample.myapp" versionName "3.0.1" versionCode 301 } } } 

父应用程序的风格不会自动传播到Wear项目。 你必须明确地映射它。

而不是这个:

 dependencies { wearApp project(':myWearApp') } 

做这个:

在您的Wear应用程序中:

 android { publishNonDefault true } 

在你的父应用程序中:

 dependencies { TrialWearApp project(path: ':myWearApp', configuration: 'Trial') FullWearApp project(path: ':myWearApp', configuration: 'Full') } 

我发现你find了一个解决你的问题的方法,但是这里是我的版本,它将编译configuration与风格和应用程序后缀结合在一起,以防将来可能需要这些configuration。 也可能是那些最终用Googlesearch这个post的人的相关信息。

应用程序/的build.gradle:

 android { compileSdkVersion 23 buildToolsVersion '23.0.3' signingConfigs { debug { ... } release { ... } } defaultConfig { applicationId "com.sample.myapp" minSdkVersion 14 targetSdkVersion 23 versionName "3.0.1" versionCode 301 } buildTypes { debug { applicationIdSuffix ".debug" embedMicroApp = true minifyEnabled false debuggable true } release { embedMicroApp = true minifyEnabled true zipAlignEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } productFlavors { trial { applicationIdSuffix ".trial" } full { applicationIdSuffix ".pro" } } } configurations { trialDebugWearApp fullDebugWearApp trialReleaseWearApp fullReleaseWearApp } dependencies { ... trialDebugWearApp project(path: ':myWearApp', configuration: 'trialDebug') fullDebugWearApp project(path: ':myWearApp', configuration: 'fullDebug') trialReleaseWearApp project(path: ':myWearApp', configuration: 'trialRelease') fullReleaseWearApp project(path: ':myWearApp', configuration: 'fullRelease') } 

穿/的build.gradle:

 android { compileSdkVersion 23 buildToolsVersion '23.0.3' publishNonDefault true signingConfigs { debug { ... } release { ... } } defaultConfig { applicationId "com.sample.myapp" minSdkVersion 20 targetSdkVersion 23 versionName "3.0.1" versionCode 301 } buildTypes { debug { applicationIdSuffix ".debug" minifyEnabled false debuggable true } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } productFlavors { trial { applicationIdSuffix ".trial" } full { applicationIdSuffix ".pro" } } dependencies { ... } } 

我会多加一点@ tormod的答案,因为他忽略了一些关键点,包括publishNonDefault true


下面是一些示例Gradle文件,用于打包磨损模块的风味和构buildtypes。

模块移动build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId "com.example.app" minSdkVersion 15 targetSdkVersion 23 versionCode 85 versionName "2.5.2" } buildTypes { debug { applicationIdSuffix ".debug" embedMicroApp = true minifyEnabled false } release { embedMicroApp = true shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' zipAlignEnabled true } } productFlavors { free{ applicationId "com.example.app" } pro{ applicationId "com.example.app.pro" } } } configurations { freeDebugWearApp proDebugWearApp freeReleaseWearApp proReleaseWearApp } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' freeDebugWearApp project(path: ':wear', configuration: 'freeDebug') proDebugWearApp project(path: ':wear', configuration: 'proDebug') freeReleaseWearApp project(path: ':wear', configuration: 'freeRelease') proReleaseWearApp project(path: ':wear', configuration: 'proRelease') } 

模块磨损build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" publishNonDefault true defaultConfig { applicationId "com.example.app" minSdkVersion 20 targetSdkVersion 23 versionCode 85 versionName "2.5.2" } buildTypes { debug { applicationIdSuffix ".debug" minifyEnabled false } release { shrinkResources true minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' zipAlignEnabled true } } productFlavors { free { applicationId "com.example.app" } pro { applicationId "com.example.app.pro" } } } dependencies { ... }