React-native-onesignal: Google Play 服务库错误

创建于 2018-05-21  ·  37评论  ·  资料来源: OneSignal/react-native-onesignal

描述:

注册的设备在 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"
  }

重现问题的步骤:

  1. 反应原生初始化 OneSignalTest
  2. cd OneSignalTest
  3. 纱线安装
  4. yarn add react-native-onesignal
  5. 反应原生链接
  6. 关注: https: //documentation.onesignal.com/docs#section -android-specific-instructions
  7. 在 android/app/build.gradle 上,在依赖项上插入compile project(':react-native-onesignal') 。 没有这种依赖就无法编译。
  8. 在 App.js 类上,插入侦听器: https ://documentation.onesignal.com/docs#section -usage
  9. 在 ComponentWillMount 上插入此 OneSignal.configure(); 强制返回 onIds。
    在 Ids listener 上,擦除类方法并创建一个本地方法,这样我们就可以看到 id。
    如果我们不这样做,id 将永远不会返回
OneSignal.addEventListener('ids', device => {
      console.log('[OneSignal]>>ids: ', device);
    });

在初始化时插入您的应用 ID。

  1. 然后:react-native run-android。
    (在 adb logcat 上它会返回一个错误,但你会在调试模式下设置 id。)
  2. 在 OneSignal Dashboard 上搜索 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)

googleplayserviceserror

编辑1:
我试过做这些,但没有成功:

最有用的评论

@brunoandradebr @DaniloCouto @ifanfaizal我修复了,我更改了 sdkVersion 和版本 appcompat

变化:
应用程序/build.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 (android)

// 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 中卸载应用程序并使用 react-native 进行编译

所有37条评论

@DaniloCouto这绝对是一个 android 支持库版本问题。 你能发布你的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很抱歉听到这个消息,但我也在这里寻找解决方案......
我试图追随那些没有成功的人:

达尼洛,你应该插入
android:launchMode="singleTop"
内部活动上下文不在应用程序中作为一个信号指令。
顺便说一句,它也不好用=[

@brunoandradebr很好地观察了我的同胞。
正如你所说,它仍然无法正常工作。

compile "com.google.android.gms:play-services-gcm:+"

在从 android studio sdk manager 安装 Google Play Service 后将此添加到依赖项,并且以某种方式工作,但是应用程序崩溃了,然后我刷新了 onesignal 用户列表并且错误一直存在 =[

我认为它现在正在工作! 我从 Android Studio 安装了 Google Play Service,它不应该插入任何行,你需要关闭 bundle 并重新编译。 它显示订阅了一个复选图标! 我什至没有插入 onesignal 额外的行,这与 react native 创建的方式相同。

@brunoandradebr @DaniloCouto @ifanfaizal我修复了,我更改了 sdkVersion 和版本 appcompat

变化:
应用程序/build.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 (android)

// 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 中卸载应用程序并使用 react-native 进行编译

@lahed Aaaahhh它正在工作,兄弟! 💃 非常感谢您的解决方案.. 我花了 3 天的时间使它工作,但根本没有结果.. 今天,您只是救了我的命😃

@lahed ,就像一个魅力,谢谢。
估计是关门了……?
OneSignal 团队可以对此做些什么?
改进的反应原生链接?

@lahed ty,它的工作

我有 2 个项目使用一个信号
项目 1 不需要 OneSignal.init
但项目 2 需要 OneSignal.init
任何人都可以解释吗?

@stevanus1997也许你已经在项目 2 的 build.gradle 上定义了 init(?)(换句话说,你用旧的方式定义了 OneSignal init)所以你不需要在 App.js 中再次初始化

项目一

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

@lahed 非常感谢。 现在它像魅力一样工作......!!!

我遵循了@lahed的解决方案,但我仍然从 OneSignal 的仪表板中得到同样的错误......有人可以告诉我他的固定android/build.gradleandroid/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" }
    }
}

在一个信号列表中,删除实际设备选项>删除,卸载调试应用程序然后再次编译。

+1 没有收到来自反应原生 js 的带有 init 调用的 onIds

@congnguyen91这是意料之中的。 onIds事件只会在订阅状态(id)实际改变时触发。

如果要强制onIds触发,可以在初始化后调用OneSignal.configure() 。 这很令人困惑,我知道,这是遗产。 我们将在下一个主要版本中进行重构,以减少混乱。

@lahed ,我是否看到您提出的更改正确https://github.com/geektimecoil/react-native-onesignal/issues/525#issuecomment -392224930,最小。 需要compileSdkVersionbuildToolsVersion现在是 26 (这意味着Android 8.0 )? (与设置指南中的注释相匹配:https://documentation.onesignal.com/v5.0/docs/react-native-sdk-setup#section-adding-the-gradle-plugin)。

这是否意味着不再支持 Android 6.x,因为我当前的compileSdkVersionbuildToolsVersion是 23 和 23.0.2。

谢谢你的帮助!

@natterstefan我几乎可以肯定不是。 定义较低设备的是 minSdkVersion,因此,除非不支持原生 API,否则一切都应该完美运行。 我在 Android 4.4 上测试过,效果很好

我在这里解决了......
我依次卸载了google play服务包和onesignal。
在此之后,我安装了 onesignal,现在一切正常。
Ps:查看构建后创建的档案并验证是否存在 google play services dll。
P2s:我将 onesignal 与 xamarin 应用程序一起使用。

我们更新了文档以确保compileSdkVersionbuildToolsVersion为 26+。
https://documentation.onesignal.com/docs/react-native-sdk-setup#section -adding-the-gradle-plugin

这是@lahedhttps://github.com/geektimecoil/react-native-onesignal/issues/525#issuecomment -392224930 中建议的事情之一。

另一个新部分是将 OneSignal Gradle 插件添加到您的项目中。 有了这个,您不必手动更新appcompat-v7中的app/build.gradle并解决其他插件中版本冲突的问题。

在创建新问题或在此处回复之前,请确保您已遵循新的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 文档到了 bell 并且有
应用插件:'com.onesignal.androidsdk.onesignal-gradle-plugin'

其他信息:
毕业 3.1.3
分机{
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
minSdkVersion = 16
targetSdkVersion = 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"
  }
}

安卓/build.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' }
    }
}

android/app/build.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/debug/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>

此页面是否有帮助?
0 / 5 - 0 等级