Skip to content

Commit ba283fa

Browse files
committed
feat: add codePush
1 parent 6f12ac9 commit ba283fa

File tree

10 files changed

+577
-227
lines changed

10 files changed

+577
-227
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ dist/
7575
# @end expo-cli
7676

7777
#secret
78-
android/app/src/main/assets/appcenter-config.json
78+
android/app/src/main/assets/appcenter-config.json
79+
#env
80+
.env

android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ project.ext.react = [
8585
]
8686

8787
apply from: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../react.gradle")
88+
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
8889

8990
/**
9091
* Set this to true to create two separate APKs instead of one:

android/app/src/main/java/com/xianshenglu/xyz/MainApplication.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.lang.reflect.InvocationTargetException;
2121
import java.util.List;
2222

23+
import com.microsoft.codepush.react.CodePush;
24+
2325
public class MainApplication extends Application implements ReactApplication {
2426
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
2527
this,
@@ -42,6 +44,11 @@ protected List<ReactPackage> getPackages() {
4244
protected String getJSMainModuleName() {
4345
return "index";
4446
}
47+
48+
@Override
49+
protected String getJSBundleFile() {
50+
return CodePush.getJSBundleFile();
51+
}
4552
});
4653

4754
@Override

android/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
<string name="expo_splash_screen_status_bar_translucent" translatable="false">false</string>
55
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">DO_NOT_ASK_JAVASCRIPT</string>
66
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
7+
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
78
</resources>

android/settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ useExpoModules()
66
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
77
applyNativeModulesSettingsGradle(settings)
88

9-
include ':app'
9+
include ':app', ':react-native-code-push'
10+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

gen-app-center-config.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import { registerRootComponent } from 'expo';
2-
2+
import codePush from "react-native-code-push";
33
import App from './App';
44

5+
loadDevEnv();
6+
7+
const codePushOptions = {
8+
updateDialog: true,
9+
deploymentKey: process.env.CODE_PUSH_DEPLOYMENT_KEY,
10+
};
511
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
612
// It also ensures that whether you load the app in Expo Go or in a native build,
713
// the environment is set up appropriately
8-
registerRootComponent(App);
14+
registerRootComponent(codePush(codePushOptions)(App));
15+
16+
function loadDevEnv() {
17+
if (!process.env.NODE_ENV) {
18+
dotenv.config();
19+
}
20+
}

0 commit comments

Comments
 (0)