ReactNative开发之打包发布

1.发布android.apk

原生打包方式为 :Android Studio 找到Build -> Generate Signed APK...

rn需要用命令行方式

cd android && ./gradlew assembleRelease

2.发布ios.ipa

选择release

5.png

3.android的VersionCode和VersionName

Google为APK定义了两个关于版本属性:VersionCode和VersionName,他们有不同的用途。

  • VersionCode:对消费者不可见,仅用于应用市场、程序内部识别版本,判断新旧等用途。
  • VersionName:展示给消费者,消费者会通过它认知自己安装的版本,下文提到的版本号都是说VersionName。

4.ios Xcode上Version和Build

  • Version(应用程序发布版本号)
  • Build(应用程序内部标示)

参考链接

  • https://developer.android.google.cn/about/versions/nougat/android-7.0.html#apk_signature_v2

  • 在Mac平台上利用Android Studio对应用签名打包

  • iOS开发-Xcode Debug、Release、Archive、Profile、Analyze概念解释

  • ReactNative之Android打包APK方法(趟坑过程

  • android开发中关于VersionCode和VersionName

  • Android Studio 中修改versionCode跟versionName

  • Xcode上Version和Build

5.android studio 使用命令行打包的时候出现 bash gradle command not found

mac 下的 bash gradle command not found

6.Android Studio之bash: gradlew: command not found

Android Studio之bash: gradlew: command not found

7.Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get m

Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get m

8.android studio 3.0 运行react-native-update失败

Error:Execution failed for task ':react-native-update:compileDebugNdk'.
> Error: Your project contains C++ files but it is not using a supported native build system.
  Consider using CMake or ndk-build integration. For more information, go to:
   https://d.android.com/r/studio-ui/add-native-code.html
  Alternatively, you can use the experimental plugin:
   https://developer.android.com/r/tools/experimental-plugin.html

在项目的gradle.properties文件中加入这句

android.useDeprecatedNdk=true

在你导入的包含jni的库的build.gradle文件中加入这句

sourceSets.main {
    jni.srcDirs = []
}

参考链接

  • android studio使用jni ndk会出现的问题

9.android 编译

Native module UpdateModule tried to override UpdateModule for module name RCTHotUpdate. If this was your intention, set canOverrideExistingModule=true

删除MainApplication.java下重复的包

  1. Xcode 打包的时候提示: select a method for export

1).Save for iOS App Store Deployment
上传App Store 或者在越狱的iOS设备上使用

2).Save for Ad Hoc Deployment
证书包含udid 的设备使用

3).Save for Enterprise Deployment
针对企业级账户

40.Save for Development Deployment
内部测试使用,证书包含udid 的设备使用

fir.im只支持 AdHoc 或 InHouse打包

11.Android 编译修改打包Apk文件名

applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
            //Android 修改打包文件名
            variant.outputs.all {
                outputFileName = "app-${variant.name}-${variant.versionName}.apk"
            }
        }
    }

还可以加入时间

def releaseTime() {
    return new Date().format("yyyy-MM-dd_HH:mm", TimeZone.getDefault())
}

渠道

flavorDimensions "default"
    productFlavors {
        qihu360 {dimension "default"} // 360手机助手
        yingyongbao {dimension "default"} // 腾讯应用宝
        fir_im {dimension "default"} // 豌豆荚
    }

加入渠道的方式只适用于原始,在rn中使用编译会出现请问难题

variant.outputs.all {
                outputFileName = "app-${variant.name}-${variant.versionName}(${variant.versionCode})-${releaseTime()}.apk"
            }

参考链接

  • Android Studio修改打包输出apk文件名
  • Cannot set the value of read-only property 'outputFile'

12.XCode打开Archive界面

window ->organizer
Tunes Store Operation Failed
ERROR ITMS-90096: "Your binary is not optimized for iPhone 5 - New iPhone apps and app updates submitted must support the 4-inch display on iPhone 5 and must include a launch image referenced in the Info.plist under UILaunchImages with a UILaunchImageSize value set to {320, 568}. Launch images must be PNG files and located at the top-level of your bundle, or provided within each .lproj folder if you localize your launch images. Learn more about iPhone 5 support and app launch images by reviewing the 'iOS Human Interface Guidelines' at https://developer.apple.com/ios/human-interface-guidelines/graphics/launch-screen."

参考链接

  • app提交App Store 报错(一)
WARNING ITMS-90704: "Missing App Store Icon. iOS Apps must include a 1024x1024px App Store Icon in PNG format. Without providing the icon in the Asset Catalog or via iTunes Connect, apps cannot be submitted for App Review or Beta App Review. Refer to https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/app-icon/ for more information."

需要一张 1024 X 1024的icon

参考链接

  • Missing Marketing Icon. iOS Apps must include a 1024x1024px Marketing Icon in PNG format.
Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

意思就是plist必须包含上面字符串的键值对向用户解释应用程序如何使用这些数据。

找到原因、iOS10之后、苹果对app使用用户权限更严格

参考链接

  • app上线,ipa包上传成功,但是iTunes里边不现实构建版本的问题原因

16.AppStore IPV6
rn是支持的
参考链接

  • iOS-不用网线搭建IPv6网络测试环境

Could not list contents of 'XXX'

Couldn't follow symbolic link.的错误.

参考链接

  • 'Couldn't follow symbolic link' when testing release build for Android

18.查看android .jks文件信息

keytool -list -v -keystore [jks文件-全路径]
* What went wrong:
Execution failed for task ':app:bundleReleaseJsAndAssets'.
> A problem occurred starting process 'command 'node''
6.png

这个错误的可能原因是gradle deamon的缓存问题,关掉cradle deamon,重新再执行一次就可以解决。

$ ./gradlew --stop

还是无效尝试下边方法

gradle.properties中加入

NODE_PATH=/usr/local/bin/node

build.gradle中

project.ext.react = [
    nodeExecutableAndArgs: hasProperty('NODE_PATH')?[NODE_PATH]:null
]
7.png

参考链接

  • React Native遇见的几个坑
  • react.gradle file not bundling Js code
java.lang.RuntimeException: com.facebook.react.devsupport.JSException: Attempted to redefine property 'right'. (index.android.bundle:765)

这个错误发生在android 打包release上,如果网上所有解决方案都不行的时候可以尝试下,首先在index.android.bundle文件中定位765行,看属于哪个文件,在工程中查找right是否在一个{}中被赋值两次。

因为是release版本,所以日志没法看,如果Android Stuido 也无法查看日志可以使用adb命令

 adb logcat *:E //查看错误log

adb logcat -t1000 *:E //查看最近1000行错误log
8.png
Error type 3

Error: Activity class {com.xx.xx/com.xx.xx.MainActivity} does not exist.

依旧检查没有错误且尝试网上所有方法都无效情况下,猜测是否与多渠道打包配置有关

注释后编译通过,

//     flavorDimensions "default"
//     productFlavors {
// //        qihu360 {dimension "default"} // 360手机助手
// //        yingyongbao {dimension "default"} // 腾讯应用宝
//         fir_im {dimension "default"} // 豌豆荚
//     }
To run dex in process, the Gradle daemon needs a larger heap.
It currently has 1024 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB.
To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

取消注释这条线在 gradle.properties:

参考链接

  • A larger heap for the Gradle daemon is recommended for running jack
* What went wrong:
Execution failed for task ':app:transformDexWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/coreutils/BuildConfig;

在build.gradle中添加

multiDexEnabled true

参考链接

  • Android导入三方SDK时遇到的一些异常及解决方案

博客原文

你可能感兴趣的:(ReactNative开发之打包发布)