4

我試圖根據反應本機代碼的推文檔Codepush陣營Android本地staging-任務installReleaseStagingDebug根項目未發現

我的build.gradle文件中有這樣的this section配置我的RN的Android項目配置:

buildTypes { 
     debug { 
     } 
     releaseStaging { 
      buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING 
     } 
     release { 
      buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_PRODUCTION 
      minifyEnabled enableProguardInReleaseBuilds 
      proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 
      signingConfig signingConfigs.release 
     } 
    } 

但是當我運行:react-native run-android --variant releaseStaging

我得到的錯誤:Task 'installReleaseStagingDebug' not found in root project 'MyAppName'.

還試圖運行react-native run-android --configuration releaseStaging

這給了我一個稍微好一點的錯誤:

Task 'installReleaseStaging' not found in root project 'MyAppName'. Some candidates are: 'uninstallReleaseStaging'. 

任何想法,我缺少的是什麼?
謝謝!
Uri

回答

6

您必須將signingConfig添加到releaseStaging中。

releaseStaging { 
     signingConfig signingConfigs.release 
     buildConfigField "String", "CODEPUSH_KEY", CODEPUSH_KEY_STAGING 
    } 

然後,您可以將它安裝到您的設備。我有反應本機版本0.38,所以我安裝它與react-native run-android --variant=releaseStaging,但這可能是不同的其他反應原生版本。如果您有更新版本的react-native,則可以改爲使用react-native run-android --configuration=releaseStaging

0

Android的搖籃插件允許你定義自定義的配置設置爲每「建設型」(例如調試,釋放)

要這樣設置, 修改的Android /應用/的build.gradle標準陣營的本機項目

android { 
... 
buildTypes { 
    debug { 
     ... 
     // Note: CodePush updates should not be tested in Debug mode as they are overriden by the RN packager. However, because CodePush checks for updates in all modes, we must supply a key. 
     buildConfigField "String", "CODEPUSH_KEY", '""' 
     ... 
    } 

    releaseStaging { 
     ... 
     buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_STAGING_KEY>"' 
     signingConfig signingConfigs.release 
     ... 
    } 

    release { 
     ... 
     buildConfigField "String", "CODEPUSH_KEY", '"<INSERT_PRODUCTION_KEY>"' 
     signingConfig signingConfigs.release 
     ... 
    } 
} 
... 

}

注: CodePush更新不應該在調試模式下進行測試,因爲它們是由RN打包覆蓋。但是,由於CodePush在所有模式下檢查更新,我們必須提供密鑰。

buildConfigField "String", "CODEPUSH_KEY", '""'

對於最新的反應母語;你可以用

`react-native run-android --variant releaseStaging`