Last active
July 8, 2019 13:43
-
-
Save danmartens/a8a17d4db9c5bbbe08b332a8ac660e3a to your computer and use it in GitHub Desktop.
Urban Airship/Gimbal Android Integration
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
import * as React from 'react'; | |
import { UrbanAirship } from 'urbanairship-react-native'; | |
class App extends React.Component { | |
componentDidMount() { | |
UrbanAirship.setUserNotificationsEnabled(true); | |
UrbanAirship.setLocationEnabled(true); | |
} | |
render() { | |
return null; | |
} | |
} |
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
apply plugin: "com.android.application" | |
import com.android.build.OutputFile | |
project.ext.react = [ | |
entryFile: "index.js" | |
] | |
apply from: "../../node_modules/react-native/react.gradle" | |
/** | |
* Set this to true to create two separate APKs instead of one: | |
* - An APK that only works on ARM devices | |
* - An APK that only works on x86 devices | |
* The advantage is the size of the APK is reduced by about 4MB. | |
* Upload all the APKs to the Play Store and people will download | |
* the correct one based on the CPU architecture of their device. | |
*/ | |
def enableSeparateBuildPerCPUArchitecture = true | |
/** | |
* Run Proguard to shrink the Java bytecode in release builds. | |
*/ | |
def enableProguardInReleaseBuilds = false | |
android { | |
compileSdkVersion rootProject.ext.compileSdkVersion | |
compileOptions { | |
sourceCompatibility JavaVersion.VERSION_1_8 | |
targetCompatibility JavaVersion.VERSION_1_8 | |
} | |
defaultConfig { | |
applicationId "com.xxxxxx.xxxxxx" | |
minSdkVersion rootProject.ext.minSdkVersion | |
targetSdkVersion rootProject.ext.targetSdkVersion | |
multiDexEnabled true | |
versionCode 1 | |
versionName "1.0.0" | |
} | |
splits { | |
abi { | |
reset() | |
enable enableSeparateBuildPerCPUArchitecture | |
universalApk true // If true, also generate a universal APK | |
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" | |
} | |
} | |
buildTypes { | |
release { | |
minifyEnabled enableProguardInReleaseBuilds | |
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" | |
signingConfig signingConfigs.release | |
} | |
} | |
// applicationVariants are e.g. debug, release | |
applicationVariants.all { variant -> | |
variant.outputs.each { output -> | |
// For each separate APK per architecture, set a unique version code as described here: | |
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits | |
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4] | |
def abi = output.getFilter(OutputFile.ABI) | |
if (abi != null) { // null for the universal-debug, universal-release variants | |
output.versionCodeOverride = | |
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode | |
} | |
} | |
} | |
} | |
dependencies { | |
implementation 'com.google.firebase:firebase-core:16.0.9' | |
implementation project(':bugsnag-react-native') | |
implementation project(':urbanairship-react-native') | |
implementation project(':react-native-svg') | |
implementation project(':@react-native-community_async-storage') | |
implementation project(':react-native-screens') | |
implementation project(':react-native-webview') | |
implementation project(':react-native-gesture-handler') | |
implementation project(':react-native-device-info') | |
implementation fileTree(dir: "libs", include: ["*.jar"]) | |
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" | |
implementation "com.facebook.react:react-native:+" // From node_modules | |
implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0' | |
implementation 'com.google.android.gms:play-services-location:16.0.0' | |
implementation 'com.google.firebase:firebase-messaging:17.4.0' | |
implementation('com.urbanairship.android:gimbal-adapter:2.2.0') { | |
exclude group: 'com.gimbal.android.v3' | |
} | |
implementation 'com.gimbal.android.v4:gimbal-sdk:4.0.1' | |
implementation 'com.gimbal.android.v4:gimbal-slf4j-impl:4.0.1' | |
} | |
apply plugin: 'com.google.gms.google-services' |
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
package com.xxxxxx.xxxxxx; | |
import android.app.Application; | |
import com.facebook.react.ReactApplication; | |
import com.horcrux.svg.SvgPackage; | |
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage; | |
import com.swmansion.rnscreens.RNScreensPackage; | |
import com.reactnativecommunity.webview.RNCWebViewPackage; | |
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage; | |
import com.learnium.RNDeviceInfo.RNDeviceInfo; | |
import com.facebook.react.ReactNativeHost; | |
import com.facebook.react.ReactPackage; | |
import com.facebook.react.shell.MainReactPackage; | |
import com.facebook.soloader.SoLoader; | |
import com.bugsnag.BugsnagReactNative; | |
import com.urbanairship.reactnative.ReactAirshipPackage; | |
import com.urbanairship.gimbal.GimbalAdapter; | |
import com.gimbal.android.Gimbal; | |
import java.util.Arrays; | |
import java.util.List; | |
public class MainApplication extends Application implements ReactApplication { | |
private static final String GIMBAL_APP_API_KEY = "xxxxxx-xxxxxx-xxxxxx-xxxxxx"; | |
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { | |
@Override | |
public boolean getUseDeveloperSupport() { | |
return BuildConfig.DEBUG; | |
} | |
@Override | |
protected List<ReactPackage> getPackages() { | |
return Arrays.<ReactPackage>asList( | |
new MainReactPackage(), | |
new SvgPackage(), | |
new AsyncStoragePackage(), | |
new RNScreensPackage(), | |
new RNCWebViewPackage(), | |
new RNGestureHandlerPackage(), | |
new ReactAirshipPackage() | |
); | |
} | |
@Override | |
protected String getJSMainModuleName() { | |
return "index"; | |
} | |
}; | |
@Override | |
public ReactNativeHost getReactNativeHost() { | |
return mReactNativeHost; | |
} | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
SoLoader.init(this, /* native exopackage */ false); | |
GimbalAdapter.shared(this).startWithPermissionPrompt(GIMBAL_APP_API_KEY, new GimbalAdapter.PermissionResultCallback() { | |
@Override | |
public void onResult(boolean enabled) { | |
if (enabled) { | |
// permission granted and adapter started | |
} | |
} | |
}); | |
} | |
} |
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
rootProject.name = 'XXXXXX' | |
include ':app' | |
include ':bugsnag-react-native' | |
project(':bugsnag-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/bugsnag-react-native/android') | |
include ':react-native-svg' | |
project(':react-native-svg').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-svg/android') | |
include ':@react-native-community_async-storage' | |
project(':@react-native-community_async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/async-storage/android') | |
include ':react-native-screens' | |
project(':react-native-screens').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-screens/android') | |
include ':react-native-webview' | |
project(':react-native-webview').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview/android') | |
include ':react-native-gesture-handler' | |
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android') | |
include ':urbanairship-react-native' | |
project(':urbanairship-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/urbanairship-react-native/android') | |
include ':react-native-device-info' | |
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment