Skip to content

Commit d1e9d5e

Browse files
committed
react-native example: restore Android .java classes, remove Kotlin
1 parent 2892a16 commit d1e9d5e

File tree

8 files changed

+162
-68
lines changed

8 files changed

+162
-68
lines changed

examples/sdk/reactNative/android/app/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: "com.android.application"
2-
apply plugin: "org.jetbrains.kotlin.android"
32
apply plugin: "com.facebook.react"
43

54
/**
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.reactnative;
2+
3+
import com.facebook.react.ReactPackage;
4+
import com.facebook.react.bridge.NativeModule;
5+
import com.facebook.react.bridge.ReactApplicationContext;
6+
import com.facebook.react.uimanager.ViewManager;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collections;
10+
import java.util.List;
11+
12+
public class BacktraceDemoPackage implements ReactPackage {
13+
@Override
14+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
15+
return Collections.emptyList();
16+
}
17+
18+
@Override
19+
public List<NativeModule> createNativeModules(
20+
ReactApplicationContext reactContext) {
21+
List<NativeModule> modules = new ArrayList<>();
22+
23+
modules.add(new ErrorGenerator(reactContext));
24+
25+
return modules;
26+
}
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.reactnative;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
5+
import com.facebook.react.bridge.ReactMethod;
6+
7+
import java.io.File;
8+
import java.io.FileReader;
9+
import java.io.IOException;
10+
11+
import android.util.Log;
12+
13+
public class ErrorGenerator extends ReactContextBaseJavaModule {
14+
ErrorGenerator(ReactApplicationContext context) {
15+
super(context);
16+
}
17+
18+
@Override
19+
public String getName() {
20+
return "ErrorGenerator";
21+
}
22+
23+
@ReactMethod
24+
public void test() {
25+
Log.d("dupa", "biskupa");
26+
return;
27+
}
28+
29+
@ReactMethod
30+
public void throwError() throws IOException {
31+
readUserConfiguration();
32+
}
33+
34+
private void readUserConfiguration() throws IOException {
35+
// I know for sure this file is there (spoiler alert, it's not)
36+
File mConfiguration = new File("configuration.json");
37+
FileReader mConfigurationDataReader = new FileReader(mConfiguration);
38+
char[] configurationDataBuffer = new char[255];
39+
mConfigurationDataReader.read(configurationDataBuffer);
40+
}
41+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.reactnative;
2+
3+
import com.facebook.react.ReactActivity;
4+
import com.facebook.react.ReactActivityDelegate;
5+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
6+
import com.facebook.react.defaults.DefaultReactActivityDelegate;
7+
8+
public class MainActivity extends ReactActivity {
9+
10+
/**
11+
* Returns the name of the main component registered from JavaScript. This is used to schedule
12+
* rendering of the component.
13+
*/
14+
@Override
15+
protected String getMainComponentName() {
16+
return "reactNative";
17+
}
18+
19+
/**
20+
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
21+
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
22+
* (aka React 18) with two boolean flags.
23+
*/
24+
@Override
25+
protected ReactActivityDelegate createReactActivityDelegate() {
26+
return new DefaultReactActivityDelegate(
27+
this,
28+
getMainComponentName(),
29+
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
30+
DefaultNewArchitectureEntryPoint.getFabricEnabled());
31+
}
32+
}

examples/sdk/reactNative/android/app/src/main/java/com/reactnative/MainActivity.kt

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.reactnative;
2+
3+
import android.app.Application;
4+
import com.facebook.react.PackageList;
5+
import com.facebook.react.ReactApplication;
6+
import com.facebook.react.ReactNativeHost;
7+
import com.facebook.react.ReactPackage;
8+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
9+
import com.facebook.react.defaults.DefaultReactNativeHost;
10+
import com.facebook.soloader.SoLoader;
11+
import java.util.List;
12+
13+
public class MainApplication extends Application implements ReactApplication {
14+
15+
private final ReactNativeHost mReactNativeHost = new DefaultReactNativeHost(this) {
16+
@Override
17+
public boolean getUseDeveloperSupport() {
18+
return BuildConfig.DEBUG;
19+
}
20+
21+
@Override
22+
protected List<ReactPackage> getPackages() {
23+
@SuppressWarnings("UnnecessaryLocalVariable")
24+
List<ReactPackage> packages = new PackageList(this).getPackages();
25+
// Packages that cannot be autolinked yet can be added manually here, for
26+
// example:
27+
packages.add(new BacktraceDemoPackage());
28+
return packages;
29+
}
30+
31+
@Override
32+
protected String getJSMainModuleName() {
33+
return "index";
34+
}
35+
36+
@Override
37+
protected boolean isNewArchEnabled() {
38+
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
39+
}
40+
41+
@Override
42+
protected Boolean isHermesEnabled() {
43+
return BuildConfig.IS_HERMES_ENABLED;
44+
}
45+
};
46+
47+
@Override
48+
public ReactNativeHost getReactNativeHost() {
49+
return mReactNativeHost;
50+
}
51+
52+
@Override
53+
public void onCreate() {
54+
super.onCreate();
55+
SoLoader.init(this, /* native exopackage */ false);
56+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
57+
// If you opted-in for the New Architecture, we load the native entry point for
58+
// this app.
59+
DefaultNewArchitectureEntryPoint.load();
60+
}
61+
}
62+
}

examples/sdk/reactNative/android/app/src/main/java/com/reactnative/MainApplication.kt

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

examples/sdk/reactNative/android/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ buildscript {
55
compileSdkVersion = 34
66
targetSdkVersion = 34
77
ndkVersion = "26.1.10909125"
8-
kotlinVersion = "1.9.24"
98
}
109
repositories {
1110
google()
@@ -14,7 +13,6 @@ buildscript {
1413
dependencies {
1514
classpath("com.android.tools.build:gradle")
1615
classpath("com.facebook.react:react-native-gradle-plugin")
17-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
1816
}
1917
}
2018

0 commit comments

Comments
 (0)