Skip to content

Commit

Permalink
feat: add codePush
Browse files Browse the repository at this point in the history
  • Loading branch information
xianshenglu committed Mar 7, 2023
1 parent 6f12ac9 commit ba283fa
Show file tree
Hide file tree
Showing 10 changed files with 577 additions and 227 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,6 @@ dist/
# @end expo-cli

#secret
android/app/src/main/assets/appcenter-config.json
android/app/src/main/assets/appcenter-config.json
#env
.env
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ project.ext.react = [
]

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

/**
* Set this to true to create two separate APKs instead of one:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import com.microsoft.codepush.react.CodePush;

public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
this,
Expand All @@ -42,6 +44,11 @@ protected List<ReactPackage> getPackages() {
protected String getJSMainModuleName() {
return "index";
}

@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
}
});

@Override
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
<string name="expo_splash_screen_status_bar_translucent" translatable="false">false</string>
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">DO_NOT_ASK_JAVASCRIPT</string>
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
</resources>
3 changes: 2 additions & 1 deletion android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ useExpoModules()
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle");
applyNativeModulesSettingsGradle(settings)

include ':app'
include ':app', ':react-native-code-push'
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')
10 changes: 0 additions & 10 deletions gen-app-center-config.ts

This file was deleted.

16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { registerRootComponent } from 'expo';

import codePush from "react-native-code-push";
import App from './App';

loadDevEnv();

const codePushOptions = {
updateDialog: true,
deploymentKey: process.env.CODE_PUSH_DEPLOYMENT_KEY,
};
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
// It also ensures that whether you load the app in Expo Go or in a native build,
// the environment is set up appropriately
registerRootComponent(App);
registerRootComponent(codePush(codePushOptions)(App));

function loadDevEnv() {
if (!process.env.NODE_ENV) {
dotenv.config();
}
}
Loading

0 comments on commit ba283fa

Please sign in to comment.