Skip to content

Commit

Permalink
[templates] Update templates for the next SDK (#14409)
Browse files Browse the repository at this point in the history
# Why

Update templates for the next SDK

# How

- `et update-project-templates`
- manually updated some dependencies like `react`, `react-dom`, `react-native`, `react-native-web`, `@types/react`
- migrated bare template from unimodules to expo modules
- [android] migrate unimodules to expo-modules
- [android] integrate ReactNativeHostWrapper / ReactActivityDelegateWrapper
- replace splash screen integration by in-module setup
- replace expo-updates integration by in-module setup
- add Podfile.properties.json with hermes support
- fix other `node_modules` resolution where breaking monorepo support, e.g. hermes-engine or maven repo. 
- use mavenCentral before jcenter because [jcenter will be a read-only mirror repository](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/)

 Co-authored-by: Tomasz Sapeta <tomasz.sapeta@swmansion.com>
 Co-authored-by: Cedric van Putten <me@bycedric.com>

# Test Plan

```sh
expo init -t /path/to/templates/expo-template-bare-minimum sdk43
cd sdk43
expo run:android
expo run:android --variant release
expo run:ios
expo run:ios --configuration Release
```
  • Loading branch information
Kudo committed Sep 20, 2021
1 parent bebd6d8 commit 9781212
Show file tree
Hide file tree
Showing 19 changed files with 6,191 additions and 7,688 deletions.
11 changes: 4 additions & 7 deletions templates/expo-template-bare-minimum/android/app/build.gradle
Expand Up @@ -79,11 +79,10 @@ import com.android.build.OutputFile

project.ext.react = [
enableHermes: (findProperty('expo.jsEngine') ?: "jsc") == "hermes",
cliPath: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute().text.trim(), "../cli.js"),
]

apply from: new File(["node", "--print", "require.resolve('react-native-unimodules/package.json')"].execute().text.trim(), "../gradle.groovy")
apply from: new File(["node", "--print", "require.resolve('react-native/package.json')"].execute().text.trim(), "../react.gradle")
apply from: new File(["node", "--print", "require.resolve('expo-updates/package.json')"].execute().text.trim(), "../scripts/create-manifest-android.gradle")

/**
* Set this to true to create two separate APKs instead of one:
Expand Down Expand Up @@ -223,12 +222,10 @@ dependencies {
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
addUnimodulesDependencies()

if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
debugImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute().text.trim(), "../android/hermes-debug.aar"))
releaseImplementation files(new File(["node", "--print", "require.resolve('hermes-engine/package.json')"].execute().text.trim(), "../android/hermes-release.aar"))
} else {
implementation jscFlavor
}
Expand All @@ -241,5 +238,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
into 'libs'
}

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json"].execute().text.trim(), "../native_modules.gradle");
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute().text.trim(), "../native_modules.gradle");
applyNativeModulesAppBuildGradle(project)
Expand Up @@ -7,8 +7,7 @@
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;
import expo.modules.ReactActivityDelegateWrapper;

public class MainActivity extends ReactActivity {
@Override
Expand All @@ -18,28 +17,26 @@ protected void onCreate(Bundle savedInstanceState) {
// This is required for expo-splash-screen.
setTheme(R.style.AppTheme);
super.onCreate(null);
// SplashScreen.show(...) has to be called after super.onCreate(...)
// Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually
SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, false);
}

/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "main";
}

/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "main";
}

@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
};
}
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new ReactActivityDelegateWrapper(
this,
new ReactActivityDelegate(this, getMainComponentName()) {
@Override
protected ReactRootView createRootView() {
return new RNGestureHandlerEnabledRootView(MainActivity.this);
}
});
}
}
Expand Up @@ -2,47 +2,40 @@

import android.app.Application;
import android.content.Context;
import android.net.Uri;
import android.content.res.Configuration;
import androidx.annotation.NonNull;

import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.helloworld.generated.BasePackageList;

import org.unimodules.adapters.react.ReactAdapterPackage;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.Package;
import org.unimodules.core.interfaces.SingletonModule;
import expo.modules.updates.UpdatesController;
import expo.modules.ApplicationLifecycleDispatcher;
import expo.modules.ReactNativeHostWrapper;

import com.facebook.react.bridge.JSIModulePackage;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;

public class MainApplication extends Application implements ReactApplication {
private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
new BasePackageList().getPackageList()
);

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
private final ReactNativeHost mReactNativeHost = new ReactNativeHostWrapper(
this,
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}

Expand All @@ -55,25 +48,7 @@ protected String getJSMainModuleName() {
protected JSIModulePackage getJSIModulePackage() {
return new ReanimatedJSIModulePackage();
}

@Override
protected @Nullable String getJSBundleFile() {
if (BuildConfig.DEBUG) {
return super.getJSBundleFile();
} else {
return UpdatesController.getInstance().getLaunchAssetFile();
}
}

@Override
protected @Nullable String getBundleAssetName() {
if (BuildConfig.DEBUG) {
return super.getBundleAssetName();
} else {
return UpdatesController.getInstance().getBundleAssetName();
}
}
};
});

@Override
public ReactNativeHost getReactNativeHost() {
Expand All @@ -85,11 +60,14 @@ public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);

if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}

initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
ApplicationLifecycleDispatcher.onApplicationCreate(this);
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions templates/expo-template-bare-minimum/android/build.gradle
Expand Up @@ -9,6 +9,7 @@ buildscript {
}
repositories {
google()
mavenCentral()
jcenter()
}
dependencies {
Expand All @@ -24,14 +25,15 @@ allprojects {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
url(new File(["node", "--print", "require.resolve('react-native/package.json')"].execute().text.trim(), "../android"))
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
url(new File(["node", "--print", "require.resolve('jsc-android/package.json')"].execute().text.trim(), "../dist"))
}

google()
mavenCentral()
jcenter()
maven { url 'https://www.jitpack.io' }
}
Expand Down
6 changes: 3 additions & 3 deletions templates/expo-template-bare-minimum/android/settings.gradle
@@ -1,9 +1,9 @@
rootProject.name = 'HelloWorld'

apply from: new File(["node", "--print", "require.resolve('react-native-unimodules/package.json')"].execute().text.trim(), "../gradle.groovy");
includeUnimodulesProjects()
apply from: new File(["node", "--print", "require.resolve('expo/package.json')"].execute().text.trim(), "../scripts/autolinking.gradle");
useExpoModules()

apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json"].execute().text.trim(), "../native_modules.gradle");
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute().text.trim(), "../native_modules.gradle");
applyNativeModulesSettingsGradle(settings)

include ':app'

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -1,10 +1,9 @@
#import <Foundation/Foundation.h>
#import <EXUpdates/EXUpdatesAppController.h>
#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>

#import <UMCore/UMAppDelegateWrapper.h>
#import <Expo/Expo.h>

@interface AppDelegate : UMAppDelegateWrapper <RCTBridgeDelegate, EXUpdatesAppControllerDelegate>
@interface AppDelegate : EXAppDelegateWrapper <RCTBridgeDelegate>

@end

0 comments on commit 9781212

Please sign in to comment.