Skip to content

Commit

Permalink
chore: add working hardcoded Android config
Browse files Browse the repository at this point in the history
  • Loading branch information
edeckers committed May 4, 2022
1 parent 49bffb3 commit 23f151d
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 43 deletions.
2 changes: 1 addition & 1 deletion android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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/")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String, ReactModuleInfo> = HashMap()
Log.i(TAG,"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB")
// val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
val isTurboModule = true
moduleInfos[LIBRARY_NAME] = ReactModuleInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,6 +24,7 @@ protected String getMainComponentName() {
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
Log.i(TAG, "DDDDDDDDDDDDDDDDDD");
return new MainActivityDelegate(this, getMainComponentName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -34,37 +36,38 @@ protected List<ReactPackage> getPackages() {
List<ReactPackage> 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;
}

@Override
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 =
new MainApplicationReactNativeHost(this);

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -49,6 +51,9 @@ protected List<ReactPackage> 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;
Expand Down
8 changes: 4 additions & 4 deletions example/android/app/src/main/jni/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 := \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MainApplicationModuleProvider.h"
#include <blob_courier.h>

#include <rncore.h>
#include <blob_courier.h>

namespace facebook {
namespace react {
Expand All @@ -13,16 +13,11 @@ std::shared_ptr<TurboModule> 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);
}

Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,14 @@
"module",
"typescript"
]
},
"codegenConfig": {
"libraries": [
{
"name": "RNBlobCourierSpec",
"type": "modules",
"jsSrcsDir": "src"
}
]
}
}
2 changes: 1 addition & 1 deletion src/NativeBlobCourier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export interface Spec extends TurboModule {
uploadBlob(input: Object): Promise<Object>;
}

export default TurboModuleRegistry.get<Spec>('BlobCourier');
export default TurboModuleRegistry.getEnforcing<Spec>('BlobCourier');

0 comments on commit 23f151d

Please sign in to comment.