React Native Android打包apk

按照官方的5步曲:

1.在终端里面,cd 到项目的根目录后.执行下面这行命令:

keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
然后终端就会让你输入口令等信息.如

React Native Android打包apk_第1张图片

2.执行第一步会在根目录下会生成一个XXXXXX.keystore的文件,直接拿到android/app下.

React Native Android打包apk_第2张图片

3.在android/gradle.properties中加入:

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添加下面的红色字.
def enableProguardInReleaseBuilds = true

android {
...

defaultConfig {

....

}
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}}
splits {

....

}
buildTypes {
    release {
        signingConfig signingConfigs.release
       ...
    }
}

.....

        }
    }
}

}

5.终端cd 到android目录下.执行命令

./gradlew assembleRelease

等一下终端执行后显示BUILD SUCCESSFUL.

成功打好了.在项目的android/app/outputs/apk下可见刚才打好的apk包
React Native Android打包apk_第3张图片

你可能感兴趣的:(打包apk,react-native)