【react-native】android 打包方法记录

web前端发展到今天,可以说已经跨多个平台了, 从一开始的响应式页面,到现在的打包app,pcApp等等已经变为现实了,这个方式方式还是在4年前的方式,可能有新的版本了,或者新的方式。这块就回忆下怎么使用 react-native 打包app的步骤。不变的步骤

版本:react-native-cli: 2.0.1

  • react-native bundle
react-native bundle 
--platform android 
--dev false 
--entry-file 
index.android.js 
--bundle-output android/bundle/index.android.bundle  
--assets-dest android/assets

注意的地方:把 index.android.bundle 放在 app/src/main/assets 目录下。
如果需要热更新可以把 bundle 放服务器上保证能访问到 以后可以更新bundle文件, 这个没亲测过。

  • 生成keystore
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
  • 设置 android/gradle.properties 变量 这块下一步会用到
MYAPP_RELEASE_STORE_FILE=android.keystore	
MYAPP_RELEASE_KEY_ALIAS=icon.ibeeger.com	
MYAPP_RELEASE_STORE_PASSWORD=*****    
MYAPP_RELEASE_KEY_PASSWORD=*****
  • 编辑 android/app/build.gradle

这里有一篇文章介绍https://blog.csdn.net/u010983881/article/details/50009839 sdk 和 android 版本的关系,供大家查阅。

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.reactnative"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

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

    buildTypes {
        release {
            minifyEnabled false  // Set this to true to enable Proguard
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
}

// 这块是依赖第三方 rn组件
dependencies {
    compile project(':react-native-device-info')
    compile project(':react-native-tts')
    compile project(':react-native-vector-icons')
    compile project(':react-native-wechat')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

最后配置好之后 运行

./android/gradlew  assembleRelease 
./android/gradlew installRelease 

打包到/android/app/build/outputs/apk 这里
真正发布的时候 可能还要加固,各个商店都有不通的加固工具。不加固审核不通过

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值