μ€λͺ
:
λ±λ‘λ κΈ°κΈ°λ OneSignal λμ보λμ μ€λ₯λ₯Ό λ°ννλ―λ‘ νΈμ μλ¦Όμ λ°μ μ μμ΅λλ€.
νκ²½
react-native -v
react-native-cli: 2.0.1
react-native: 0.55.4
ν¨ν€μ§.json
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-onesignal": "^3.2.3"
}
λ¬Έμ μ¬ν λ¨κ³:
compile project(':react-native-onesignal')
λ₯Ό μ½μ
ν©λλ€. κ·Έ μμ‘΄μ± μμ΄λ μ»΄νμΌν μ μμ΅λλ€.OneSignal.addEventListener('ids', device => {
console.log('[OneSignal]>>ids: ', device);
});
Initμμ μ± IDλ₯Ό μ½μ νμμμ€.
κΈ°ν:
E/OneSignal(31234): Unknown error getting FCM Token
E/OneSignal(31234): java.lang.NoSuchMethodError: No static method isDeviceProtectedStorage(Landroid/content/Context;)Z in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/com.onesignaltest-1/base.apk)
E/OneSignal(31234): at com.google.firebase.FirebaseApp.zza(Unknown Source)
E/OneSignal(31234): at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
E/OneSignal(31234): at com.onesignal.PushRegistratorFCM.initFirebaseApp(PushRegistratorFCM.java:64)
E/OneSignal(31234): at com.onesignal.PushRegistratorFCM.getToken(PushRegistratorFCM.java:50)
E/OneSignal(31234): at com.onesignal.PushRegistratorAbstractGoogle.attemptRegistration(PushRegistratorAbstractGoogle.java:97)
E/OneSignal(31234): at com.onesignal.PushRegistratorAbstractGoogle.access$100(PushRegistratorAbstractGoogle.java:37)
E/OneSignal(31234): at com.onesignal.PushRegistratorAbstractGoogle$1.run(PushRegistratorAbstractGoogle.java:84)
E/OneSignal(31234): at java.lang.Thread.run(Thread.java:818)
νΈμ§ 1:
λλ κ·Έκ²λ€μ μλνμ§λ§ μ±κ³΅νμ§ λͺ»νμ΅λλ€.
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
μΆκ°@DaniloCouto μ΄κ²μ νμ€ν μλλ‘μ΄λ μ§μ λΌμ΄λΈλ¬λ¦¬ λ²μ λ¬Έμ μ
λλ€. app/build.gradle
λ₯Ό κ²μν μ μμ΅λκΉ?
@DaniloCouto λ μ λ²μ 3.2.4λ₯Ό νμΈνκ³ μμ ν©λλ€.
@adirzoari , μ¬μ ν 3.2.4μμ λ°μνλ©° Adb logcat λ° Onesignal μ¬μ©μ λμ보λμμ λμΌν μ€λ₯κ° λ°μν©λλ€.
yarn add [email protected]
ν¨ν€μ§.json
"dependencies": {
"react": "16.3.1",
"react-native": "0.55.4",
"react-native-onesignal": "3.2.4"
},
@Nightsd01 λ¬Όλ‘ μ
λλ€. μ¬κΈ° μμ΅λλ€:
app/build.gradle
(μμ±λ λκΈμ μμ νμ΅λλ€)
apply plugin: "com.android.application"
import com.android.build.OutputFile
project.ext.react = [
entryFile: "index.js"
]
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.onesignaltest"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
applicationVariants.all { variant ->
variant.outputs.each { output ->
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) {
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
}
dependencies {
compile project(':react-native-onesignal') // I just added this line
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+"
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
νΈμ§ 1:
νμΌ μμ λΆλΆμ μΆκ°νμ΅λλ€. μ무κ²λ λ³νμ§ μμλ€:
buildscript {
repositories {
maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
}
dependencies {
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.0, 0.99.99]'
}
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
...
...
...
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
...
...
}
λ¬Όλ‘ gradlew clean
λ‘ Android νλ‘μ νΈλ₯Ό μ 리νκ³ λ€μ λΉλνλ €κ³ νμ΅λλ€.
@DaniloCouto react-native-onesignal example
νλ‘μ νΈλ₯Ό μ¬μ©νκ³ κ³μλμ...?
AndroidManifest.xml
νμΌλ κ²μν μ μμ΅λκΉ? κ°μ¬ ν΄μ
@Nightsd01 μλ‘μ΄ react-native νλ‘μ νΈλ₯Ό λ§λ€κ³ Yarnμ ν΅ν΄ react-native-onesignal ν¨ν€μ§λ₯Ό μΆκ°νμ΅λλ€.
μ¬κΈ°μμ΄:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.onesignaltest">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <!-- Onesignal Instruction -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <!-- Onesignal Instruction -->
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme"
> <!-- android:launchMode="singleTop" I Was wrong at this line-->
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:launchMode="singleTop"> <!-- brunoandradebr made a pretty nice observation right here -->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
νΈμ§ 1:
#387 μ루μ
μ μ΄μ΄ μ΄ λΌμΈμ μΆκ°νμ΅λλ€. μ무κ²λ λ³νμ§ μμλ€
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
νΈμ§ 2:
@brunoandradebr μμ μ μ μλ―μ΄ android:launchMode="singleTop"
λ μ ν리μΌμ΄μ
νκ·Έκ° μλ νλ νκ·Έμ μμ΄μΌ ν©λλ€.
νμ§λ§ μ¬μ ν μλνμ§ μμ΅λλ€..
μ¬κΈ°μ κ°μ λ¬Έμ κ° μμ΅λλ€. @DaniloCouto λΉμ μ΄ κ·Έκ²μ κ³ μ³€μ΅λκΉ ???
λλ κ°μ λ¬Έμ κ° μμ΅λλ€. @DaniloCouto λΉμ μ κ·Έκ²μ κ³ μΉ μ μμμ΅λκΉ? μ¬κΈ°μ κΈ° κ²μνλλ° μμ§ μλμ΄ μλλ€μ :(
@ifanfaizal , @lahed μ£μ‘ν©λλ€λ§, μ λ ν΄κ²°μ±
μ μ°ΎκΈ° μν΄ μ¬κΈ° μμ΅λλ€...
λλ μ±κ³΅ νμ§ λͺ»ν μ¬λλ€μ λ°λ₯΄λ €κ³ λ
Έλ ₯νμ΅λλ€.
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
μΆκ°λ€λλ‘, λΉμ μ μ½μ
ν΄μΌν©λλ€
android:launchMode="singleTop"
νλμ μ νΈ λͺ
λ ΉμΌλ‘ μμ© νλ‘κ·Έλ¨μ μλ λ΄λΆ νλ 컨ν
μ€νΈ.
Btw μ μλνμ§ μμ΅λλ€ =[
@brunoandradebr λ΄ λν¬λ₯Ό μ κ΄μ°°νμ΅λλ€.
λΉμ μ΄ λ§νλ―μ΄, κ·Έκ²μ μ¬μ ν ββββμλνμ§ μμ΅λλ€.
compile "com.google.android.gms:play-services-gcm:+"
Android studio sdk κ΄λ¦¬μμμ Google Play μλΉμ€λ₯Ό μ€μΉν ν μ’ μμ±μ μΆκ°νκ³ μ΄λ»κ²λ μλνμ§λ§ μ±μ΄ μΆ©λν λ€μ onesignal μ¬μ©μ λͺ©λ‘μ μλ‘ κ³ μ³€κ³ μ€λ₯κ° κ³μ μ§μλ©λλ€. =[
μ§κΈ μλνλ κ² κ°μμ! Android Studioμμ Google Play μλΉμ€λ₯Ό μ€μΉνμ΅λλ€. ν μ€λ μ½μ νμ§ μμμΌ νλ―λ‘ λ²λ€μ λ«κ³ λ€μ μ»΄νμΌν΄μΌ ν©λλ€. μ²΄ν¬ μμ΄μ½μΌλ‘ ꡬλ μ€μ΄λΌκ³ νμλ©λλ€! onesignal μΆκ° λΌμΈμ μ½μ νμ§λ μμλλ°, react nativeκ° μμ±ν κ²κ³Ό κ°μ λ°©μμ λλ€.
@brunoandradebr @DaniloCouto @ifanfaizal μμ ν©λλ€. sdkVersion λ° λ²μ appcompatμ λ³κ²½ν©λλ€.
λ³κ²½ μ¬ν:
μ±/λΉλ.gradle
compileSdkVersion 26
buildToolsVersion "26.0.2"
μ’
μμ±
λ³ν
compile "com.android.support:appcompat-v7:23.0.1"
μκ²
compile "com.android.support:appcompat-v7:26.0.1"
λ΄ build.gradle(μλλ‘μ΄λ)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven { // <-- THIS
url 'https://maven.google.com/' // <-- THIS
name 'Google' // <-- THIS
} // <-- THIS
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven { // <-- THIS
url 'https://maven.google.com/' // <-- THIS
name 'Google' // <-- THIS
} // <-- THIS
}
}
cmdμμ: cd android && gradlew clean
λ΄ AVDμμ μ±μ μ κ±°νκ³ λ°μ λ€μ΄ν°λΈλ‘ μ»΄νμΌ
@lahed μμμμμ μλνκ³ μμ΄ ν!! π ν΄κ²°ν΄ μ£Όμ μ μ λ§ κ°μ¬ν©λλ€.. 3μΌ λμ μμ νμ§λ§ κ²°κ³Όκ° μ ν μμμ΅λλ€. κ·Έλ¦¬κ³ μ€λ, λΉμ μ λ¨μ§ λ΄ μλͺ μ ꡬνμ΅λλ€ π
@lahed , 맀λ ₯μ²λΌ μλν©λλ€.
λ«μκ±° κ°μλ°...?
OneSignal νμ μ΄μ λν΄ λ¬΄μμ ν μ μμ΅λκΉ?
ν₯μλ λ°μ λ€μ΄ν°λΈ λ§ν¬ ?
@lahed ty, κ·Έ μΌ
νλμ μ νΈλ₯Ό μ¬μ©νλ 2κ°μ νλ‘μ νΈκ° μμ΅λλ€.
νλ‘μ νΈ 1 νμ μμ OneSignal.init
κ·Έλ¬λ νλ‘μ νΈ 2λ OneSignal.initκ° νμν©λλ€.
μ무λ κ·Έκ²μ μ€λͺ
ν μ μμ΅λκΉ?
@stevanus1997 μλ§λ λΉμ μ μ΄λ―Έ νλ‘μ νΈ 2(?)μ build.gradleμ μ΄κΈ°νλ₯Ό μ μνμ μ μμ΅λλ€(μ¦, μ΄μ λ°©μμΌλ‘ OneSignal μ΄κΈ°νλ₯Ό μ μνμ΅λλ€). λ°λΌμ App.jsμμ λ€μ μ΄κΈ°νν νμκ° μμμ΅λλ€.
νλ‘μ νΈ 1
defaultConfig {
applicationId "com.xxxxx"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
onesignal_app_id: "xxxxxxxxx",
onesignal_google_project_number: "xxxxxxxxx"
]
}
νλ‘μ νΈ 2
defaultConfig {
applicationId "com.xxxx"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [
onesignal_app_id : "xxxxx",
onesignal_google_project_number: "xxxxx"
]
multiDexEnabled true
}
@ifanfaizalμ λ΄ build.gradleμ λλ€.
@lah μ λ§ κ°μ¬ν©λλ€. μ΄μ 맀λ ₯μ²λΌ μλν©λλ€...!!!
@lahed μ μ루μ
μ λ°λμ§λ§ μ¬μ ν OneSignalμ λμ보λμμ λμΌν μ€λ₯κ° λ°μν©λλ€. λκ΅°κ° κ³ μ λ android/build.gradle
λ° android/app/build.gradle
λ₯Ό λμκ² λ³΄μ¬μ€ μ μμ΅λκΉ?
μ»΄νμΌλ¬λ₯Ό λ«κ³ λ€μ μ»΄νμΌνμμμ€.
λ²μ¨ μ¬λ¬λ² νλ€μ π
Android Studioμ ν¨κ» Google Play μλΉμ€λ₯Ό μ€μΉνμ ¨μ΅λκΉ?
λ€, μ΅μ λ²μ μ λλ€. Android 8.0μμ μ€ν μ€μ λλ€.
android/app/build.gradle
:
apply plugin: "com.android.application"
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
import com.android.build.OutputFile
apply from: "../../node_modules/react-native/react.gradle"
def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "xxx"
minSdkVersion 16
targetSdkVersion 27
versionCode 31
versionName "0.3.0"
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [manifestApplicationId: "${applicationId}",
onesignal_google_project_number: "xxx"]
}
signingConfigs {
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
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]
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
}
}
}
}
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile project(':react-native-image-picker')
compile(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile 'com.google.android.gms:play-services-base:+'
compile 'com.google.android.gms:play-services-maps:+'
compile project(':react-native-svg')
compile project(':react-native-dialogs')
compile project(':react-native-onesignal')
compile fileTree(dir: "libs", include: ["*.jar"])
compile project(':react-native-vector-icons')
compile project(':react-native-i18n')
compile project(':react-native-fetch-blob')
compile (project(':react-native-camera')) {
exclude group: "com.android.support"
exclude group: "com.google.android.gms"
}
compile ("com.google.android.gms:play-services-vision:+") {
force = true;
}
compile ('com.android.support:exifinterface:27.0.2') {
force = true;
}
compile "com.android.support:appcompat-v7:27.0.2"
compile 'com.android.support:support-vector-drawable:27.0.2'
compile 'com.android.support:animated-vector-drawable:27.0.2'
compile "com.facebook.react:react-native:+" // From node_modules
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
android/build.gradle
:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.10.1, 0.99.99]'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
jcenter()
maven { url "$rootDir/../node_modules/react-native/android" }
maven {
url "https://maven.google.com"
name 'Google'
}
maven { url "https://jitpack.io" }
}
}
νλμ μ νΈ λͺ©λ‘ λ΄μμ μ€μ μ₯μΉ Option > μμ λ₯Ό μ κ±°νκ³ λλ²κ·Έ μ±μ μ κ±°ν λ€μ λ€μ μ»΄νμΌνμμμ€.
+1 λ°μ λ€μ΄ν°λΈ jsμμ μ΄κΈ°ν νΈμΆλ‘ onIdsλ₯Ό μμ νμ§ μμ
@congnguyen91 μμλ©λλ€. onIds
μ΄λ²€νΈλ ꡬλ
μν(id's)κ° μ€μ λ‘ λ³κ²½λ λλ§ λ°μν©λλ€.
onIds
λ₯Ό κ°μ λ‘ μ€νμν€λ €λ©΄ μ΄κΈ°ν ν OneSignal.configure()
λ₯Ό νΈμΆνλ©΄ λ©λλ€. μ΄κ²μ νΌλμ€λ½μ΅λλ€. μ λ μκ³ μμ΅λλ€. μ μ°μ
λλ€. μ°λ¦¬λ μ΄κ²μ λ νΌλμ€λ½κ² λ§λ€κΈ° μν΄ λ€μ μ£Όμ 릴리μ€μμ 리ν©ν λ§ν κ²μ
λλ€.
@lahedλ , μλ
νμΈμ. μ μλ λ³κ²½ μ¬νμ λ³΄κ³ μμ΅λκΉ? https://github.com/geektimecoil/react-native-onesignal/issues/525#issuecomment -392224930, min. νμν compileSdkVersion
λ° buildToolsVersion
λ μ΄μ 26μ
λλ€( Android 8.0 μ μλ―Έ)? (μ€μ κ°μ΄λμ μ°Έκ³ μ¬νκ³Ό μΌμΉ: https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup#section-adding-the-gradle-plugin).
μ΄κ²μ νμ¬ compileSdkVersion
λ° buildToolsVersion
κ° 23 λ° 23.0.2μ΄κΈ° λλ¬Έμ Android 6.xκ° λ μ΄μ μ§μλμ§ μλλ€λ κ²μ μλ―Έν©λκΉ?
λΉμ μ λμμ μ£Όμ μ κ°μ¬ν©λλ€!
@natterstefan κ±°μ νμ€νμ§ μμ΅λλ€. νμ μ₯μΉλ₯Ό μ μνλ κ²μ minSdkVersionμ΄λ―λ‘ κΈ°λ³Έ APIκ° μ§μλμ§ μλ ν λͺ¨λ κ²μ΄ μλ²½νκ² μλν©λλ€. Android 4.4μμ ν μ€νΈνλλ° μ μλν©λλ€.
μ¬κΈ°μ ν΄κ²°νμ΅λλ€....
Google Play μλΉμ€ ν¨ν€μ§μ onesignalμ μ°¨λ‘λ‘ μ κ±°νμ΅λλ€.
μ΄ ν onesignalμ μ€μΉνκ³ λͺ¨λ κ²μ΄ μ΄μ μλν©λλ€.
μΆμ : λΉλ ν μμ±λ μμΉ΄μ΄λΈλ₯Ό μ΄ν΄λ³΄κ³ google play services dllμ΄ μλμ§ νμΈνμμμ€.
P2s: μ λ xamarin μ ν리μΌμ΄μ
κ³Ό ν¨κ» onesignalμ μ¬μ©νκ³ μμ΅λλ€.
compileSdkVersion
λ° buildToolsVersion
κ° 26μΈ μ΄μμΈμ§ νμΈνλ λ΄μ©μ ν¬ν¨νλλ‘ μ€λͺ
μλ₯Ό μ
λ°μ΄νΈνμ΅λλ€.
https://documentation.onesignal.com/docs/react-native-sdk-setup#section -adding-the-gradle-plugin
μ΄κ²μ @lahedκ° https://github.com/geektimecoil/react-native-onesignal/issues/525#issuecomment -392224930 μμ μ μν κ² μ€ νλμ λλ€.
λ€λ₯Έ μλ‘μ΄ λΆλΆμ OneSignal Gradle νλ¬κ·ΈμΈμ νλ‘μ νΈμ μΆκ°νλ κ²μ
λλ€. μ΄λ κ² νλ©΄ app/build.gradle
appcompat-v7
λ₯Ό μλμΌλ‘ μ
λ°μ΄νΈν νμκ° μκ³ λ€λ₯Έ νλ¬κ·ΈμΈμμ μΆ©λνλ λ²μ λ¬Έμ λ₯Ό ν΄κ²°ν μ μμ΅λλ€.
μ λ¬Έμ λ₯Ό μμ±νκ±°λ λμΌν λ¬Έμ κ° νμλλ κ²½μ° μ¬κΈ°μ νμ νκΈ° μ μ μλ‘μ΄ Adding the Gradle Plugin
μΉμ
μ λ°λλμ§ νμΈνμμμ€.
@lahed μ λ§ κ°μ¬ν©λλ€. μ΄ λ¬Έμ λ₯Ό 2μΌ λμ μμλ΄λ €κ³ λ Έλ ₯νκ³ λ§μΉ¨λ΄ μ¬κΈ°μμ λ§€μ° μ μ©ν λ¬Έμ λ₯Ό μ°Ύμμ΅λλ€. κ°μ¬ν©λλ€.
λλ κ°μ κ²μ κ°μ§κ³ μμμ§λ§ λ€μκ³Ό κ°μ΄ onesignal.configure()λ₯Ό νΈμΆνμ¬ μλνκ² νμ΅λλ€.
OneSignal.init("my-onesignal-id");
OneSignal.configure();
μ΄κ²μ λ€μκ³Ό ν¨κ»νμ΅λλ€.
"λ°μ λ€μ΄ν°λΈ": "~0.56.0",
"react-native-onesignal": "^3.2.6",
μ’
μ λν onesignal λ¬Έμλ₯Ό λ°λκ³
νλ¬κ·ΈμΈ μ μ©: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
λ€λ₯Έ μ 보:
κ·ΈλΌλ€ 3.1.3
λ΄μ {
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
μ΅μ SDK λ²μ = 16
λμ SDK λ²μ = 27
supportLibVersion = "27.1.1"
googlePlayServicesVersion = "12.0.1"
playServicesVersion = googlePlayServicesVersion
}
μ κ²½μ°μλ OneSignal λμ보λμμ μ€λ₯κ° λ°μνμ§ μμμ΅λλ€. μ₯μΉκ° OneSignalμ μ λ±λ‘λμμ΅λλ€. onIds
μ΄(κ°) λ°μ¬λμ§ μμμ΅λλ€.
OneSignal.init() μ§νμ μ΄κ²μ μΆκ°νλ©΄ λ΄ λ¬Έμ κ° ν΄κ²°λμμ΅λλ€.
OneSignal.configure();
μ΄κ²μ΄ λ€λ₯Έ μ¬λλ€μ λκΈ°λ₯Ό λ°λλλ€.
μ¬κΈ°μλ κ°μ λ¬Έμ
ν¨ν€μ§.json:
{
"name": "smartial",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"android-linux": "npx react-native run-android --terminal \"$PWD/shkonsole\""
},
"dependencies": {
"@react-native-community/google-signin": "^4.0.3",
"react-native-onesignal": "^3.7.3",
"@sentry/react-native": "^1.4.1",
"react-native-code-push": "^6.2.1",
"react-native-google-places": "^3.1.2",
"@react-native-community/datetimepicker": "^2.4.2",
"@react-native-community/masked-view": "^0.1.10",
"@react-navigation/material-bottom-tabs": "^5.2.12",
"@react-navigation/native": "^5.4.3",
"@react-navigation/stack": "^5.4.0",
"react-native-gesture-handler": "^1.6.1",
"native-base": "^2.13.12",
"react-native-paper": "^3.10.1",
"react-native-safe-area-context": "^2.0.3",
"react-native-reanimated": "^1.9.0",
"react-native-screens": "^2.8.0",
"apisauce": "^1.1.1",
"react-native-config": "^1.2.1",
"react-native-easy-app": "^1.7.3",
"react-native-vector-icons": "^6.6.0",
"@thallyssonklein/border-layout-react-native": "^1.0.14",
"recoil": "github:eveningkid/Recoil#react-native",
"react": "16.13.1",
"react-native": "0.63.2"
},
"devDependencies": {
"@babel/core": "^7.10.0",
"@babel/runtime": "^7.10.0",
"@bam.tech/react-native-make": "^3.0.0",
"@react-native-community/eslint-config": "^1.1.0",
"babel-jest": "^26.0.1",
"eslint": "^7.1.0",
"jest": "^26.0.1",
"metro-react-native-babel-preset": "^0.59.0",
"react-test-renderer": "16.11.0"
},
"jest": {
"preset": "react-native"
}
}
μλλ‘μ΄λ/λΉλ.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
googlePlayServicesAuthVersion = "16.0.1"
}
repositories {
google()
jcenter()
}
dependencies {
classpath('com.android.tools.build:gradle:3.6.3')
classpath 'com.google.gms:google-services:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url("$rootDir/../node_modules/react-native/android")
}
maven {
// Android JSC is installed from npm
url("$rootDir/../node_modules/jsc-android/dist")
}
google()
jcenter()
maven { url 'https://www.jitpack.io' }
}
}
μλλ‘μ΄λ/μ±/λΉλ.gradle
apply plugin: "com.android.application"
import com.android.build.OutputFile
/**
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
* and bundleReleaseJsAndAssets).
* These basically call `react-native bundle` with the correct arguments during the Android build
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
* bundle directly from the development server. Below you can see all the possible configurations
* and their defaults. If you decide to add a configuration block, make sure to add it before the
* `apply from: "../../node_modules/react-native/react.gradle"` line.
*
* project.ext.react = [
* // the name of the generated asset file containing your JS bundle
* bundleAssetName: "index.android.bundle",
*
* // the entry file for bundle generation. If none specified and
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
* // default. Can be overridden with ENTRY_FILE environment variable.
* entryFile: "index.android.js",
*
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
* bundleCommand: "ram-bundle",
*
* // whether to bundle JS and assets in debug mode
* bundleInDebug: false,
*
* // whether to bundle JS and assets in release mode
* bundleInRelease: true,
*
* // whether to bundle JS and assets in another build variant (if configured).
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
* // The configuration property can be in the following formats
* // 'bundleIn${productFlavor}${buildType}'
* // 'bundleIn${buildType}'
* // bundleInFreeDebug: true,
* // bundleInPaidRelease: true,
* // bundleInBeta: true,
*
* // whether to disable dev mode in custom build variants (by default only disabled in release)
* // for example: to disable dev mode in the staging build type (if configured)
* devDisabledInStaging: true,
* // The configuration property can be in the following formats
* // 'devDisabledIn${productFlavor}${buildType}'
* // 'devDisabledIn${buildType}'
*
* // the root of your project, i.e. where "package.json" lives
* root: "../../",
*
* // where to put the JS bundle asset in debug mode
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
*
* // where to put the JS bundle asset in release mode
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in debug mode
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
*
* // where to put drawable resources / React Native assets, e.g. the ones you use via
* // require('./image.png')), in release mode
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
*
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"],
*
* // override which node gets called and with what additional arguments
* nodeExecutableAndArgs: ["node"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/
project.ext.react = [
enableHermes: false, // clean and rebuild if changing
]
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 = false
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false
/**
* The preferred build flavor of JavaScriptCore.
*
* For example, to use the international variant, you can use:
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
*
* The international variant includes ICU i18n library and necessary data
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
* give correct results when using with locales other than en-US. Note that
* this variant is about 6MiB larger per architecture than default.
*/
def jscFlavor = 'org.webkit:android-jsc:+'
/**
* Whether to enable the Hermes VM.
*
* This should be set on project.ext.react and mirrored here. If it is not set
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
* and the benefits of using Hermes will therefore be sharply reduced.
*/
def enableHermes = project.ext.react.get("enableHermes", false);
android {
compileSdkVersion rootProject.ext.compileSdkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.smartial"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 24
versionName "3.0.9"
multiDexEnabled true
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
}
}
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
storeFile file('smartial-app.jks')
storePassword KEYSTORE_PASSWORD
keyAlias KEY_ALIAS
keyPassword KEY_PASSWORD
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://facebook.github.io/react-native/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
packagingOptions {
pickFirst "lib/armeabi-v7a/libc++_shared.so"
pickFirst "lib/arm64-v8a/libc++_shared.so"
pickFirst "lib/x86/libc++_shared.so"
pickFirst "lib/x86_64/libc++_shared.so"
}
// 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:
// https://developer.android.com/studio/build/configure-apk-splits.html
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 fileTree(dir: "libs", include: ["*.jar"])
// implementation 'com.google.android.gms:play-services-auth:18.0.0'
// implementation "com.google.android.gms:play-services-base:16.0.1"
// implementation "com.google.firebase:firebase-core:16.0.6"
// implementation "com.google.firebase:firebase-messaging:17.3.4"
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
compile 'com.android.support:multidex:1.0.1' //enter the latest version
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'
}
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
exclude group:'com.facebook.flipper'
}
if (enableHermes) {
def hermesPath = "../../node_modules/hermes-engine/android/";
debugImplementation files(hermesPath + "hermes-debug.aar")
releaseImplementation files(hermesPath + "hermes-release.aar")
} else {
implementation jscFlavor
}
implementation project(':react-native-config')
compile project(':react-native-onesignal') // I just added this line
}
// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"
apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
apply plugin: 'com.google.gms.google-services' // <--- this should be the last line
src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smartial">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
src/λλ²κ·Έ/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
</manifest>
κ°μ₯ μ μ©ν λκΈ
@brunoandradebr @DaniloCouto @ifanfaizal μμ ν©λλ€. sdkVersion λ° λ²μ appcompatμ λ³κ²½ν©λλ€.
λ³κ²½ μ¬ν:
μ±/λΉλ.gradle
μ’ μμ±
λ³ν
compile "com.android.support:appcompat-v7:23.0.1"
μκ²
compile "com.android.support:appcompat-v7:26.0.1"
λ΄ build.gradle(μλλ‘μ΄λ)
cmdμμ: cd android && gradlew clean
λ΄ AVDμμ μ±μ μ κ±°νκ³ λ°μ λ€μ΄ν°λΈλ‘ μ»΄νμΌ