diff --git a/.gitignore b/.gitignore index 8a35f1b..c738593 100644 --- a/.gitignore +++ b/.gitignore @@ -40,7 +40,6 @@ buck-out .gradle local.properties *.iml -/android/ # Node node_modules diff --git a/android/build.gradle b/android/build.gradle new file mode 100644 index 0000000..7e9c5a1 --- /dev/null +++ b/android/build.gradle @@ -0,0 +1,25 @@ + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + ndk { + abiFilters "armeabi-v7a", "x86" + } + } + lintOptions { + warning 'InvalidPackage' + } +} + +dependencies { + compile 'com.facebook.react:react-native:0.20.+' +} + \ No newline at end of file diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..50f0085 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + diff --git a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java new file mode 100644 index 0000000..fa78c14 --- /dev/null +++ b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java @@ -0,0 +1,46 @@ + +package com.apsl.versionnumber; + +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReactContextBaseJavaModule; +import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.Callback; + +import android.content.pm.ApplicationInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.pm.PackageManager; + +import java.util.HashMap; +import java.util.Map; + +public class RNVersionNumberModule extends ReactContextBaseJavaModule { + + private final ReactApplicationContext reactContext; + + private static final String APP_VERSION = "appVersion"; + private static final String APP_BUILD = "buildVersion"; + + public RNVersionNumberModule(ReactApplicationContext reactContext) { + super(reactContext); + this.reactContext = reactContext; + } + + @Override + public String getName() { + return "RNVersionNumber"; + } + + @Override + public Map getConstants() { + final Map constants = new HashMap<>(); + final PackageManager packageManager = this.reactContext.getPackageManager(); + final String packageName = this.reactContext.getPackageName(); + try { + constants.put(APP_VERSION, packageManager.getPackageInfo(packageName, 0).versionName); + constants.put(APP_BUILD, packageManager.getPackageInfo(packageName, 0).versionCode); + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + return constants; + } +} diff --git a/android/src/main/java/com/apsl/versionnumber/RNVersionNumberPackage.java b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberPackage.java new file mode 100644 index 0000000..25cac21 --- /dev/null +++ b/android/src/main/java/com/apsl/versionnumber/RNVersionNumberPackage.java @@ -0,0 +1,29 @@ + +package com.apsl.versionnumber; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import com.facebook.react.ReactPackage; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.uimanager.ViewManager; +import com.facebook.react.bridge.JavaScriptModule; + +public class RNVersionNumberPackage implements ReactPackage { + @Override + public List createNativeModules(ReactApplicationContext reactContext) { + return Arrays.asList(new RNVersionNumberModule(reactContext)); + } + + @Override + public List> createJSModules() { + return Collections.emptyList(); + } + + @Override + public List createViewManagers(ReactApplicationContext reactContext) { + return Collections.emptyList(); + } +}