Android磨损应用程序包装失败了味道

时间:2014-12-09 19:42:16

标签: android android-gradle wear-os

我有一个包含磨损应用程序的应用程序。在使用真实设备进行调试测试时,一切正常。我也可以创建发布apk,在其中包装wear apk。但只有在我的申请中只有一种风味。

我想用不同的applicationId维护两个版本的应用程序,但是虽然这个编译没有错误,但在这种情况下,两个发布apks(每种风格之一)都没有相应的磨损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'
}

欢迎任何帮助。谢谢。

4 个答案:

答案 0 :(得分:31)

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

1。)味道必须小写

2。)依赖项配置必须包含flavor Release

3。)在Wear app build gradle中,在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
    }
 }
}

答案 1 :(得分:6)

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

而不是:

dependencies {
    wearApp project(':myWearApp')
}

这样做:

在您的Wear应用中:

android {
    publishNonDefault true
}

在您的父应用中:

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

答案 2 :(得分:1)

我看到你找到了解决问题的方法,但这是我的版本,它将构建配置与风味和应用程序后缀结合起来,以备将来可能需要时使用。也可以是那些最终用谷歌搜索这篇文章的人的相关信息。

应用程序/的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 {
        ...
    }
}

答案 3 :(得分:0)

我会在@ tormod的回答中添加更多内容,因为他忽略了一些关键点,包括publishNonDefault true

以下是一些示例Gradle文件,用于打包带有风味和构造类型的磨损模块

模块移动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 {

    ...

}