0

我已尽我所能按照说明herehere。 Android调试版本(react-native run-android)按照预期在Android模拟器和我的设备上运行,即在每次新安装或更新后重新加载JS文件。但是,当我安装发布版本(react-native run-android --variant=release)时,它会显示应用程序的第一个屏幕,并且没有任何应用程序功能可以使用。我还没有尝试在iOS上安装。它好像不是从codepush加载JS文件。当我检查日志文件(在安装模拟器上的发布版本),它挂在这条线:反应本机CodePush Android发布构建不加载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。我已经部署了我的代码,以分期和生产codepush服务器和已验证它运行

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" 

和应用程序提示我安装最新的更新。但是,一旦安装完成,它就会崩溃。从那一刻起,我一直无法从代码推送服务器加载文件。任何提示,看看或如何调试这将是非常感激。我的应用程序以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

非调试应用程序总是需求即使在使用CodePush时也要包含一个JS Bundle。 CodePush的同步/更新/验证安装函数全部由JS调用,而不是从Java或ObjC/Swift调用(该应用程序要么使用codePush高阶组件来封装使用AppRegistry注册的组件,要么应用程序正在调用codePush.sync()函数或更低级别的功能来执行更新检查并安装更新)。

这里我的假设是,在写这个问题的时候,你还没有在相当一段时间内重建你的jsbundle,所以显示的版本不是最新的,很可能不包含与CodePush的集成所有,因此不会检查发布到CodePush的更新。

总结 - 构建你的android jsbundle,重新安装发布版本,一切都应该工作。