简体   繁体   中英

Android Wear 2.0 support for watch face app

I have an Android watch face app that has both mobile and wear modules.

I want to get this app ready for 2.0 update, and I've visited all the websites that Android Developers suggest, I understand almost everything that's about to change, but then comes reality, and I'm stuck with a first simple steps.

As I read here :

If you build a standalone Wear 2.0 APK and will continue to have a Wear 1.0 APK, please do both of the following:

Provide a standalone version of the Wear APK, and Continue embedding a version of the Wear APK in your phone APK

Then here we have:

If your app supports both Wear 1.x and Wear 2.0, continue embedding the Wear 1.x APK (minimum SDK version of 20, 21, or 22, or 23) in the phone APK and upload the phone APK. In addition, upload your standalone Wear 2.0 APK (which has a minimum SDK version of 24).

So as I want to keep support for Android 1.x, what do I do exactly?

How do I set SDK version numbers in modules?

Do I need to duplicate wear module with changed SDK version for building a separate wearable apk?

Gold and kingdom for anyone that has done it successfully and would present all the necessary steps for making the app compatible for current and upcoming Wear versions.

OK, I still have to confirm if what I've done works, but it should as it meets documentation and the app's already uploaded on Play console with no errors.

Changes in wearable Manifest file

<uses-feature android:name="android.hardware.type.watch" />
<application ...>
    <meta-data
        android:name="com.google.android.wearable.standalone"
        android:value="true" />
    ...
</application>

Changes in wearable Gradle file

// wearable module

dependencies {
    compile 'com.google.android.support:wearable:2.0.0'
    compile 'com.google.android.gms:play-services-wearable:10.0.1'
    ...
}

android {
    compileSdkVersion 25
    publishNonDefault true
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId = "com.example.watchface"
        minSdkVersion 20
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    productFlavors {
        wear1 {

        }
        wear2 {
            minSdkVersion 24
            versionCode 2 // +1 relatively to default value
        }
    }
    ...
}

SDK Versions:

  • compile and target = 25,
  • default min = 20 (for wear 1.x),
  • min for wear 2.0 = 24

Version codes: wear 2.0 apk will need bigger number than embeded wearable module.

NOTE that you need separate product flavors: wear1 and wear2 . You can use custom naming.

Changes in mobile Gradle file

// mobile module

dependencies {
    compile 'com.google.android.support:wearable:2.0.0'
    compile 'com.google.android.gms:play-services-wearable:10.0.1'
    ...
    wearApp project(path:':Wearable', configuration: "wear1Release")
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId = "com.example.watchface"
        minSdkVersion 18
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    ...
}

SDK Versions:

  • compile and target = 25,
  • min = 18

Version code: same as embeded wearable (1).

NOTE that you need to specify the configuration parameter of wearApp project() using product flavor for embeded apk, adding "Release" build type: wear1Release

Generate signed APKs

  • use the same signing certificate in both APKs,
  • generate mobile APK as always,
  • generate wearable APK using wearable module (you'll get an apk file for each product flavor).

Uploading APK to Google Play

  • switch to advanced mode,
  • upload mobile apk and wear2 wearable apk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM