-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Java templates (#129)
- Loading branch information
1 parent
b552564
commit e3a4c2d
Showing
26 changed files
with
386 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/create-react-native-library/templates/java-library/android/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
buildscript { | ||
if (project == rootProject) { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.5.3' | ||
} | ||
} | ||
} | ||
|
||
apply plugin: 'com.android.library' | ||
|
||
def safeExtGet(prop, fallback) { | ||
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback | ||
} | ||
|
||
android { | ||
compileSdkVersion safeExtGet('<%- project.name %>_compileSdkVersion', 29) | ||
buildToolsVersion safeExtGet('<%- project.name %>_buildToolsVersion', '29.0.2') | ||
defaultConfig { | ||
minSdkVersion safeExtGet('<%- project.name %>_minSdkVersion', 16) | ||
targetSdkVersion safeExtGet('<%- project.name %>_targetSdkVersion', 29) | ||
versionCode 1 | ||
versionName "1.0" | ||
<% if (project.cpp) { %> | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all" | ||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' | ||
} | ||
} | ||
<% } %> | ||
} | ||
<% if (project.cpp) { %> | ||
externalNativeBuild { | ||
cmake { | ||
path "CMakeLists.txt" | ||
} | ||
} | ||
<% } %> | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
} | ||
} | ||
lintOptions { | ||
disable 'GradleCompatible' | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
maven { | ||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm | ||
url("$rootDir/../node_modules/react-native/android") | ||
} | ||
google() | ||
jcenter() | ||
} | ||
|
||
dependencies { | ||
//noinspection GradleDynamicVersion | ||
implementation "com.facebook.react:react-native:+" // From node_modules | ||
} |
47 changes: 47 additions & 0 deletions
47
...a-library/android/src/main/java/com/{%- project.package %}/{%= project.name %}Module.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.<%- project.package %>; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
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.module.annotations.ReactModule; | ||
|
||
@ReactModule(name = <%- project.name %>Module.NAME) | ||
public class <%- project.name %>Module extends ReactContextBaseJavaModule { | ||
public static final String NAME = "<%- project.name %>"; | ||
|
||
public <%- project.name %>Module(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Override | ||
@NonNull | ||
public String getName() { | ||
return NAME; | ||
} | ||
|
||
<% if (project.cpp) { -%> | ||
static { | ||
try { | ||
// Used to load the 'native-lib' library on application startup. | ||
System.loadLibrary("cpp"); | ||
} catch (Exception ignored) { | ||
} | ||
} | ||
<% } -%> | ||
|
||
// Example method | ||
// See https://reactnative.dev/docs/native-modules-android | ||
@ReactMethod | ||
public void multiply(int a, int b, Promise promise) { | ||
<% if (project.cpp) { -%> | ||
promise.resolve(nativeMultiply(a, b)); | ||
<% } else { -%> | ||
promise.resolve(a * b); | ||
<% } -%> | ||
} | ||
|
||
public static native int nativeMultiply(int a, int b); | ||
} |
28 changes: 28 additions & 0 deletions
28
...-library/android/src/main/java/com/{%- project.package %}/{%= project.name %}Package.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.<%- project.package %>; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class <%- project.name %>Package implements ReactPackage { | ||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
modules.add(new <%- project.name %>Module(reactContext)); | ||
return modules; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
Oops, something went wrong.