【问题标题】:Android Studio 1.5.1, Gradle 2.8, w/ mobile & wear w/ free/paid flavorsAndroid Studio 1.5.1、Gradle 2.8,带移动设备和可穿戴设备,带免费/付费风格
【发布时间】:2015-12-31 00:52:26
【问题描述】:

我很茫然。使用 AS 1.5.1 和 Gradle 2.8,我有移动和穿戴模块。当我选择调试版本的移动和穿戴风格时,我明白我必须手动编译/运行每个版本才能在各自的设备上运行。这没有问题:调试/运行应用程序/等。

但是,对于 mobile 和 wear 版本的发布,当我没有在 mobile/wear build.gradle 文件中创建signingConfigs 部分时,AS 会在对话框底部提示我这样做有“修复”按钮。我首先使用我的磨损模块添加 keyAlias、keyPassword、storeFile 和 storePassword。然后,通过同一个对话框,我选择了唯一一个版本的 buildType 来拥有signingConfig。当我在该对话框上单击“确定”时,上一个对话框在底部的 FIX 按钮曾经是仍然存在 gradle 错误的地方有文字。我使用移动 gradle 文件执行相同的步骤,它也在对话框中指出仍然存在 gradle 错误。 Release 中磨损的结果构建/运行不会创建 android_wear_micro_apk.apk 以将其包含在移动构建中。构建移动模块时,其中没有任何磨损 apk。我的整个应用程序(移动/穿戴)最初是我手动合并到 AS 中的一组 Eclipse 项目(工作并且实际上在 Play 商店中)。

我尝试使用移动设备和穿戴设备创建一个全新的 AS 项目。当我去运行版本时,它也促使我创建了签名概念。然而,android_wear_micro_apk.apk 是在磨损编译期间创建的。此外,移动应用程序包含穿戴的 apk。移动调试 APK 和发布 APK 的大小不同,其中发布版本更大。我知道“android_wear_micro_apk.apk”文件的唯一方法是因为这个新的/精简的测试项目——否则,我的原件没有胶水。

这里是移动 build.gradle

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {
    signingConfigs {
        the_pro_mobile_config {
            keyAlias 'MY_ALIAS_PRO'
            keyPassword 'MY_PASSWORD_PRO'
            storeFile file('my_keystore_pro.keystore')
            storePassword 'MY_STORE_PASSWORD_PRO'
        }
        the_free_mobile_config {
            keyAlias 'MY_ALIAS_FREE'
            keyPassword 'MY_PASSWORD_FREE'
            storeFile file('my_keystore_free.keystore')
            storePassword 'MY_STORE_PASSWORD_FREE'
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    packagingOptions {
        exclude 'META-INF'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES/httpcore-4.0.jar'
        exclude 'META-INF/DEPENDENCIES/httpclient-4.3.6.jar'
    }
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 25
        versionName "2.0.0"

        multiDexEnabled = true
    }
    buildTypes {

        release {

            debuggable false
            jniDebuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
            zipAlignEnabled true

        }

    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
        free {
            applicationId "com.my_app.thefree"
            signingConfig signingConfigs.the_free_mobile_config
        }
        pro {
            applicationId "com.my_app.thepro"
            signingConfig signingConfigs.the_pro_mobile_config
        }
    }
}

dependencies {

    wearApp project(':wear')

    compile project(':my_license_module')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.android.support:support-annotations:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:palette-v7:23.1.1'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.android.gms:play-services-wearable:8.4.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'commons-io:commons-io:2.4'
    compile 'com.google.android.gms:play-services-ads:8.4.0'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-gcm:8.4.0'
}

这里是wear build.gradle

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {

    signingConfigs {
        the_wearable_config {
            keyAlias 'MY_ALIAS'
            keyPassword 'MY_KEYPASSWORD'
            storeFile file('my_keystore_wearable.keystore')
            storePassword 'MY_STORE_PASSWORD'
        }
    }
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 25
        versionName "2.0.0"

        multiDexEnabled = true
    }
    buildTypes {
        release {
            debuggable false
            jniDebuggable false
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
            zipAlignEnabled true
            signingConfig signingConfigs.the_wearable_config
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    productFlavors {
        free {
            applicationId "com.myapp.my_free_app"
        }
        pro {
            applicationId "com.myapp.my_pro_app"
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.support:wearable:1.3.0'
    compile 'com.google.android.gms:play-services:8.3.0'
}

【问题讨论】:

  • 您是否使用两个不同的密钥来签署您的 Wear 和您的移动应用程序?我看到这两个的密钥库在你的构建文件中是不同的......
  • 刚刚将移动设备中的两个签名配置添加到磨损的 gradle 和相同的问题中。
  • 请用您的最新更改更新您的原始帖子。
  • 在下面查看我自己的答案。

标签: android gradle wear-os android-flavors


【解决方案1】:

我解决了这个问题。还有其他关于同样问题的帖子,这就是我找到它们的地方。

先加入wear gradle文件,添加

publishNonDefault true

在文件的“android {”部分。

这些更改是针对移动 gradle 文件的。

其次,删除“wearApp project(':wear')”并替换为这两个

freeWearApp project(path:':wear', configuration: 'freeRelease')

proWearApp project(path:':wear', configuration: 'proRelease')

我正在创建 android_wear_micro_apk 并将其添加到移动 apk。

我的下一个任务是弄清楚为什么它没有自动安装以供观看。在执行 Eclipse/etc 时,这一切都再次奏效。

【讨论】:

  • 确保您的密钥相同。此外,在尝试此操作之前,请从穿戴设备中删除旧的/不同风格的应用程序。
  • 到目前为止还没有运气。即使对移动设备和 Wear 使用相同的密钥库,再次检查 Wear 应用程序是否未安装,然后重新启动 Wear 设备(LG G 手表)。啊!
  • FWIW:在调试变体中执行移动和穿戴,穿戴应用确实与移动应用通信。
猜你喜欢
  • 1970-01-01
  • 2020-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多