From 23f151df20ee7671ff5d93421284b9c526a00867 Mon Sep 17 00:00:00 2001 From: Ely Deckers Date: Wed, 4 May 2022 23:41:11 +0200 Subject: [PATCH] chore: add working hardcoded Android config --- .../org.eclipse.buildship.core.prefs | 2 +- android/build.gradle | 7 ++--- .../blob_courier/BlobCourierPackage.kt | 24 ++++++++++++----- .../blob_courier/TurboBlobCourierModule.kt | 8 ------ .../blob_courier_example/MainActivity.java | 4 +++ .../blob_courier_example/MainApplication.java | 27 ++++++++++--------- .../MainApplicationReactNativeHost.java | 5 ++++ example/android/app/src/main/jni/Android.mk | 8 +++--- .../jni/MainApplicationModuleProvider.cpp | 11 +++----- package.json | 9 +++++++ src/NativeBlobCourier.tsx | 2 +- 11 files changed, 64 insertions(+), 43 deletions(-) diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index 822ce178..2b6d83b9 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -2,7 +2,7 @@ arguments= auto.sync=false build.scans.enabled=false connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) -connection.project.dir=../example/android +connection.project.dir= eclipse.preferences.version=1 gradle.user.home= java.home=/usr/lib/jvm/java-11-openjdk-amd64 diff --git a/android/build.gradle b/android/build.gradle index 2a628c49..5c5718c6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -40,6 +40,7 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() buildConfigField "Long", "ADB_COMMAND_TIMEOUT_MILLISECONDS", ADB_COMMAND_TIMEOUT_MILLISECONDS buildConfigField "Long", "PROMISE_TIMEOUT_MILLISECONDS", PROMISE_TIMEOUT_MILLISECONDS } @@ -180,10 +181,10 @@ dependencies { if (isNewArchitectureEnabled()) { react { - codegenJavaPackageName = "io.deckers.blob_courier.spec" + codegenJavaPackageName = "io.deckers.blob_courier" libraryName = "blob_courier" jsRootDir = file("../src/") - reactRoot = rootProject.file("../node_modules/react-native/") - codegenDir = rootProject.file("../node_modules/react-native-codegen/") + // reactRoot = rootProject.file("../node_modules/react-native/") + // codegenDir = rootProject.file("../node_modules/react-native-codegen/") } } diff --git a/android/src/main/java/io/deckers/blob_courier/BlobCourierPackage.kt b/android/src/main/java/io/deckers/blob_courier/BlobCourierPackage.kt index aaee96f4..f71b3fa8 100644 --- a/android/src/main/java/io/deckers/blob_courier/BlobCourierPackage.kt +++ b/android/src/main/java/io/deckers/blob_courier/BlobCourierPackage.kt @@ -6,6 +6,7 @@ */ package io.deckers.blob_courier +import android.util.Log import com.facebook.react.TurboReactPackage import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.NativeModule @@ -14,18 +15,29 @@ import com.facebook.react.module.model.ReactModuleInfoProvider import com.facebook.react.module.model.ReactModuleInfo import java.util.HashMap +private val TAG = "BlobCourier" + class BlobCourierPackage : TurboReactPackage() { + init { + Log.i(TAG,"YYYYYYYYYYYYYYYYYY") + } + override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { - return if (name == LIBRARY_NAME) { - BlobCourierModule(reactContext) - } else { - null - } + Log.i(TAG,"XXXXXXXXXXXXXXXXXXXXXXX") + return TurboBlobCourierModule(reactContext) + + // return if (name == LIBRARY_NAME) { + // TurboBlobCourierModule(reactContext) + // } else { + // null + // } } override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { - return ReactModuleInfoProvider { + Log.i(TAG,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + return ReactModuleInfoProvider { val moduleInfos: MutableMap = HashMap() + Log.i(TAG,"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB") // val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED val isTurboModule = true moduleInfos[LIBRARY_NAME] = ReactModuleInfo( diff --git a/android/src/main/java/io/deckers/blob_courier/TurboBlobCourierModule.kt b/android/src/main/java/io/deckers/blob_courier/TurboBlobCourierModule.kt index bb4538be..a472ca1a 100644 --- a/android/src/main/java/io/deckers/blob_courier/TurboBlobCourierModule.kt +++ b/android/src/main/java/io/deckers/blob_courier/TurboBlobCourierModule.kt @@ -8,10 +8,7 @@ package io.deckers.blob_courier import com.facebook.react.bridge.Promise import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule -import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap -import com.facebook.react.module.annotations.ReactModule import com.facebook.react.modules.network.OkHttpClientProvider import io.deckers.blob_courier.cancel.CancellationParameterFactory import io.deckers.blob_courier.cancel.RequestCanceller @@ -33,7 +30,6 @@ import io.deckers.blob_courier.react.processUnexpectedException import io.deckers.blob_courier.react.toReactMap import io.deckers.blob_courier.upload.BlobUploader import io.deckers.blob_courier.upload.UploaderParameterFactory -import io.deckers.blob_courier.spec.NativeBlobCourierSpec import java.net.UnknownHostException import kotlin.concurrent.thread @@ -58,10 +54,6 @@ class TurboBlobCourierModule(private val reactContext: ReactApplicationContext) companion object { const val NAME = LIBRARY_NAME - - init { - System.loadLibrary("blob_courier_example_appmodules") - } } override fun getName(): String = LIBRARY_NAME diff --git a/example/android/app/src/main/java/io/deckers/blob_courier_example/MainActivity.java b/example/android/app/src/main/java/io/deckers/blob_courier_example/MainActivity.java index 02b1f5a2..f8bac9e1 100644 --- a/example/android/app/src/main/java/io/deckers/blob_courier_example/MainActivity.java +++ b/example/android/app/src/main/java/io/deckers/blob_courier_example/MainActivity.java @@ -1,10 +1,13 @@ package io.deckers.blob_courier_example; +import android.util.Log; import com.facebook.react.ReactActivity; import com.facebook.react.ReactActivityDelegate; import com.facebook.react.ReactRootView; + public class MainActivity extends ReactActivity { + private static final String TAG = "BlobCourier"; /** * Returns the name of the main component registered from JavaScript. This is used to schedule @@ -21,6 +24,7 @@ protected String getMainComponentName() { */ @Override protected ReactActivityDelegate createReactActivityDelegate() { + Log.i(TAG, "DDDDDDDDDDDDDDDDDD"); return new MainActivityDelegate(this, getMainComponentName()); } diff --git a/example/android/app/src/main/java/io/deckers/blob_courier_example/MainApplication.java b/example/android/app/src/main/java/io/deckers/blob_courier_example/MainApplication.java index 93476ceb..1dcd4d0b 100644 --- a/example/android/app/src/main/java/io/deckers/blob_courier_example/MainApplication.java +++ b/example/android/app/src/main/java/io/deckers/blob_courier_example/MainApplication.java @@ -2,6 +2,7 @@ import androidx.annotation.NonNull; +import android.util.Log; import android.app.Application; import android.content.Context; import com.facebook.react.PackageList; @@ -17,9 +18,10 @@ import java.lang.reflect.InvocationTargetException; import java.util.List; -// import io.deckers.blob_courier.BlobCourierPackage; +import io.deckers.blob_courier.BlobCourierPackage; public class MainApplication extends Application implements ReactApplication { + private static final String TAG = "BlobCourier"; private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @@ -34,7 +36,7 @@ protected List getPackages() { List packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: // packages.add(new MyReactNativePackage()); - // packages.add(new BlobCourierPackage()); + packages.add(new BlobCourierPackage()); return packages; } @@ -42,12 +44,12 @@ protected List getPackages() { protected String getJSMainModuleName() { return "index"; } - - @NonNull - @Override - protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboModuleManagerDelegateBuilder() { - return new MainApplicationTurboModuleManagerDelegate.Builder(); - } + + // @NonNull + // @Override + // protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboModuleManagerDelegateBuilder() { + // return new MainApplicationTurboModuleManagerDelegate.Builder(); + // } }; private final ReactNativeHost mNewArchitectureNativeHost = @@ -55,16 +57,17 @@ protected ReactPackageTurboModuleManagerDelegate.Builder getReactPackageTurboMod @Override public ReactNativeHost getReactNativeHost() { - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { + // if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { return mNewArchitectureNativeHost; - } else { - return mReactNativeHost; - } + // } else { + // return mReactNativeHost; + // } } @Override public void onCreate() { super.onCreate(); + Log.i(TAG,"CCCCCCCCCCCCCCCCCCCCCCCCCCC"); // If you opted-in for the New Architecture, we enable the TurboModule system // ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; ReactFeatureFlags.useTurboModules = true; diff --git a/example/android/app/src/main/java/io/deckers/blob_courier_example/newarchitecture/MainApplicationReactNativeHost.java b/example/android/app/src/main/java/io/deckers/blob_courier_example/newarchitecture/MainApplicationReactNativeHost.java index f7aab589..5adf0ea5 100644 --- a/example/android/app/src/main/java/io/deckers/blob_courier_example/newarchitecture/MainApplicationReactNativeHost.java +++ b/example/android/app/src/main/java/io/deckers/blob_courier_example/newarchitecture/MainApplicationReactNativeHost.java @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import io.deckers.blob_courier.BlobCourierPackage; + /** * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both * TurboModule delegates and the Fabric Renderer. @@ -49,6 +51,9 @@ protected List getPackages() { // packages.add(new MyReactNativePackage()); // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: // packages.add(new TurboReactPackage() { ... }); + + packages.add(new BlobCourierPackage()); + // If you have custom Fabric Components, their ViewManagers should also be loaded here // inside a ReactPackage. return packages; diff --git a/example/android/app/src/main/jni/Android.mk b/example/android/app/src/main/jni/Android.mk index 37cb763a..25abc992 100644 --- a/example/android/app/src/main/jni/Android.mk +++ b/example/android/app/src/main/jni/Android.mk @@ -6,7 +6,7 @@ include $(REACT_ANDROID_DIR)/Android-prebuilt.mk # will have to include the following autogenerated makefile. # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk -# Includes the MK file for `react-native-blob-courier` +# Includes the MK file for `example-library` include /home/ely/Projects/react-native-blob-courier/android/build/generated/source/codegen/jni/Android.mk @@ -25,9 +25,9 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) # will have to uncomment those lines to include the generated source # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) # -LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni -LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) -LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni +# LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni +# LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) +# LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni # Here you should add any native library you wish to depend on. LOCAL_SHARED_LIBRARIES := \ diff --git a/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp b/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp index d21dc8e5..231b6c75 100644 --- a/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +++ b/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp @@ -1,7 +1,7 @@ #include "MainApplicationModuleProvider.h" -#include #include +#include namespace facebook { namespace react { @@ -13,16 +13,11 @@ std::shared_ptr MainApplicationModuleProvider( // either your application or from external libraries. The approach to follow // is similar to the following (for a library called `samplelibrary`: // - // auto module = samplelibrary_ModuleProvider(moduleName, params); - // if (module != nullptr) { - // return module; - // } - // return rncore_ModuleProvider(moduleName, params); auto module = blob_courier_ModuleProvider(moduleName, params); if (module != nullptr) { - return module; + return module; } - + // return rncore_ModuleProvider(moduleName, params); return rncore_ModuleProvider(moduleName, params); } diff --git a/package.json b/package.json index 82a88a7c..25edb145 100644 --- a/package.json +++ b/package.json @@ -99,5 +99,14 @@ "module", "typescript" ] + }, + "codegenConfig": { + "libraries": [ + { + "name": "RNBlobCourierSpec", + "type": "modules", + "jsSrcsDir": "src" + } + ] } } diff --git a/src/NativeBlobCourier.tsx b/src/NativeBlobCourier.tsx index 071f5866..ce0b4f0c 100644 --- a/src/NativeBlobCourier.tsx +++ b/src/NativeBlobCourier.tsx @@ -10,4 +10,4 @@ export interface Spec extends TurboModule { uploadBlob(input: Object): Promise; } -export default TurboModuleRegistry.get('BlobCourier'); +export default TurboModuleRegistry.getEnforcing('BlobCourier');