我已尽力遵循here和here的说明。 Android调试版本(react-native run-android
)在Android模拟器和我的设备上按预期运行,即在每次新安装或更新后重新加载JS文件。但是,当我安装发布版本(react-native run-android --variant=release
)时,它会显示应用程序的第一个屏幕,并且所有应用程序功能都不起作用。我没试过在iOS上安装。好像它没有从codepush加载JS文件。当我检查日志文件时(在模拟器上安装发布版本时),它挂起在这一行:
[CodePush] Loading JS bundle from "assets://index.android.bundle"
我发现令人惊讶的是发布版本试图在本地加载JS包而不是检查CodePush远程服务器。我的React-native和react-native-code-push版本分别为0.45.1和3.0.1-beta。我已将我的代码部署到登台和生产代码推送服务器,并通过运行
验证了它code-push deployment ls onetext-Android -k
我还适当地配置了我的密钥。执行此操作超过10次后,有一个时刻发布安装的日志文件实际显示:
[CodePush] Loading JS bundle from "/data/user/0/com.onetext/files/CodePush/f93a24d467d53.../CodePush/index.android.bundle"
并且应用程序提示我安装最新更新。然而,一旦安装完成它就会崩溃。从那一瞬间开始,我无法从codepush服务器加载文件。任何关于在哪里寻找或如何调试这个的提示将非常感激。我的应用程序是以native-starter-kit为起点构建的。这是我的settings.gradle文件:
rootProject.name = 'OneText'
include ':react-native-onesignal'
project(':react-native-onesignal').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-onesignal/android')
include ':react-native-image-picker'
project(':react-native-image-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-picker/android')
include ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
include ':app'
build.gradle文件的相关部分:
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.onetext"
minSdkVersion 16
targetSdkVersion 22
versionCode 4
versionName "1.0.1"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [onesignal_app_id: "xxx",
onesignal_google_project_number: "xxx"]
}
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
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
debug {
buildConfigField "String", "CODEPUSH_KEY", '""'
}
releaseStaging {
buildConfigField "String", "CODEPUSH_KEY", '"H3ZFJ..."'
}
release {
buildConfigField "String", "CODEPUSH_KEY", '"r0Sx..."'
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
// applicationVariants are e.g. debug, release
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
}
}
}
}
dependencies {
compile project(':react-native-onesignal')
compile project(':react-native-image-picker')
compile project(':react-native-code-push')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
MainApplication.java:
package com.onetext;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.geektime.rnonesignalandroid.ReactNativeOneSignalPackage;
import com.microsoft.codepush.react.CodePush;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.imagepicker.ImagePickerPackage;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new ReactNativeOneSignalPackage(),
new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG), // Add/change this line.
new ImagePickerPackage()
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
}
}
答案 0 :(得分:1)
非调试应用总是需要包含JS Bundle,即使使用CodePush也是如此。 CodePush的同步/更新/验证安装功能都是从JS而不是从Java或ObjC / Swift调用的(该应用程序使用codePush高阶组件来包装使用AppRegistry注册的组件,或者应用程序正在调用codePush。 sync()函数或更低级函数执行更新检查并安装更新。
我的假设是,在撰写此问题时,您还没有在相当长的一段时间内重建您的jsbundle,因此显示的版本不是最新的,很可能根本不包含与CodePush的集成因此不会检查发布到CodePush的更新。
总结 - 构建你的android jsbundle,重新安装发布版本,一切都应该有效。