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,重新安裝發佈版本,一切都應該工作。