Tekkaman

导航

 

生成Release apk

1、使用Java SDK中的keytool生成keystore。

  Java SDK一般位于:C:\Program Files\Java\jdkx.x.x_x\bin.

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

  Note: Remember to keep your keystore file private and never commit it to version control.

2、将前一步生成的 my-release-key.keystore 放置到 android/app。

3、新建 ~/.gradle/gradle.properties(~为用户目录,如 C:\Users\xxx\)

MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****

4、编辑 android/app/build.gradle

...
android {
    ...
    defaultConfig { ... }
    signingConfigs {
        release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            ...
            signingConfig signingConfigs.release
        }
    }
}
...

----------------------通过以上4步,就完成了生成release apk的所有配置-----------------

5、生成 release apk

  cd android && ./gradlew assembleRelease

  生成的apk位于:android/app/build/outputs/apk/app-release.apk

 

参考:https://facebook.github.io/react-native/docs/signed-apk-android.html

posted on 2017-09-25 20:19  Tekkaman  阅读(2359)  评论(0编辑  收藏  举报