invertase / react-native-google-mobile-ads

React Native Google Mobile Ads enables you to monetize your app with AdMob.
https://docs.page/invertase/react-native-google-mobile-ads
Other
673 stars 135 forks source link

Android app crash with Verifier rejected class after change the targetSdkVersion from 31 to 33 or 34 #513

Closed sinclairjaza closed 7 months ago

sinclairjaza commented 9 months ago

What happened?

After change the buildToolsVersion, compileSdkVersion, targetSdkVersion and supportLibVersion in android/build.gradle from this

buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
supportLibVersion = "3390.0"

to this

buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
supportLibVersion = "33.0.0"

Android app crash directly when I open with the error bellow:

java.lang.VerifyError: Verifier rejected class io.invertase.googlemobileads.ReactNativeGoogleMobileAdsBannerAdViewManager: com.google.android.gms.ads.BaseAdView io.invertase.googlemobileads.ReactNativeGoogleMobileAdsBannerAdViewManager.initAdView(io.invertase.googlemobileads.common.ReactNativeAdView) failed to verify: com.google.android.gms.ads.BaseAdView io.invertase.googlemobileads.ReactNativeGoogleMobileAdsBannerAdViewManager.initAdView(io.invertase.googlemobileads.common.ReactNativeAdView): [0x49] register v1 has type Precise Reference: com.google.android.gms.ads.admanager.AdManagerAdView but expected Reference: com.google.android.gms.ads.BaseAdView (declaration of 'io.invertase.googlemobileads.ReactNativeGoogleMobileAdsBannerAdViewManager' appears in /data/app/~~8EnTtpJbHVzGyYOzYFfD8A==/com.myapp-RezYdKWH5ukmixCJvRA5kg==/base.apk!classes21.dex)
        at io.invertase.googlemobileads.ReactNativeGoogleMobileAdsPackage.createViewManagers(ReactNativeGoogleMobileAdsPackage.java:47)
        at com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(ReactInstanceManager.java:782)
        at com.facebook.react.CoreModulesPackage.createUIManager(CoreModulesPackage.java:184)
        at com.facebook.react.CoreModulesPackage.getModule(CoreModulesPackage.java:152)
        at com.facebook.react.TurboReactPackage$ModuleHolderProvider.get(TurboReactPackage.java:122)
        at com.facebook.react.TurboReactPackage$ModuleHolderProvider.get(TurboReactPackage.java:110)
        at com.facebook.react.bridge.ModuleHolder.create(ModuleHolder.java:188)
        at com.facebook.react.bridge.ModuleHolder.getModule(ModuleHolder.java:153)
        at com.facebook.react.bridge.NativeModuleRegistry.getModule(NativeModuleRegistry.java:148)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:479)
        at com.facebook.react.bridge.CatalystInstanceImpl.getNativeModule(CatalystInstanceImpl.java:466)
        at com.facebook.react.uimanager.UIManagerHelper.getUIManager(UIManagerHelper.java:31)
        at com.facebook.react.ReactInstanceManager.attachRootViewToInstance(ReactInstanceManager.java:1054)
        at com.facebook.react.ReactInstanceManager.setupReactContext(ReactInstanceManager.java:1012)
        at com.facebook.react.ReactInstanceManager.access$1400(ReactInstanceManager.java:125)
        at com.facebook.react.ReactInstanceManager$5$2.run(ReactInstanceManager.java:972)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:26)
        at android.os.Looper.loopOnce(Looper.java:210)
        at android.os.Looper.loop(Looper.java:299)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:225)
        at java.lang.Thread.run(Thread.java:1012)

Platforms

Android, but have not tested behavior on iOS

React Native Info

System:
    OS: macOS 13.0
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 32.62 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.19.0 - ~/.nvm/versions/node/v14.19.0/bin/node
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.0/bin/npm
    Watchman: 2023.11.20.00 - /usr/local/bin/watchman
  IDEs:
    Android Studio: 2022.2 AI-222.4459.24.2221.9862592
    Xcode: /undefined - /usr/bin/xcodebuild

Are your using Typescript?

package.json

{
  "name": "MyApp",
  "package": "com.myapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start --reset-cache",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/async-storage": "^1.6.2",
    "@react-native-community/checkbox": "^0.3.0",
    "@react-native-community/picker": "^1.5.0",
    "@react-native-community/toolbar-android": "0.2.1",
    "@react-native-community/viewpager": "^4.0.0",
    "@react-native-firebase/admob": "^11.5.0",
    "@react-native-firebase/analytics": "^11.5.0",
    "@react-native-firebase/app": "^11.5.0",
    "@react-native-firebase/auth": "^11.5.0",
    "@react-native-firebase/dynamic-links": "^11.5.0",
    "@react-native-firebase/storage": "^11.5.0",
    "axios": "^0.19.0",
    "eventemitter3": "^4.0.4",
    "linkify-it": "^4.0.1",
    "lodash": "^4.17.20",
    "lottie-ios": "^3.1.8",
    "lottie-react-native": "^3.5.0",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.31",
    "prop-types": "^15.7.2",
    "react": "^16.9.0",
    "react-native": "0.61.5",
    "react-native-action-button": "^2.8.5",
    "react-native-animatable": "^1.3.2",
    "react-native-app-intro-slider": "^4.0.4",
    "react-native-audio": "^4.3.0",
    "react-native-calendars": "^1.212.0",
    "react-native-camera": "^4.2.1",
    "react-native-check-version": "^1.0.8",
    "react-native-confirmation-code-field": "^6.7.0",
    "react-native-confirmation-code-input": "^1.0.4",
    "react-native-device-info": "^7.0.2",
    "react-native-fast-image": "^7.0.2",
    "react-native-fs": "^2.16.6",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-gifted-chat": "^0.9.11",
    "react-native-google-mobile-ads": "10.1.2",
    "react-native-hyperlink": "0.0.22",
    "react-native-i18n": "^2.0.15",
    "react-native-image-crop-picker": "^0.38.1",
    "react-native-image-picker": "^2.3.1",
    "react-native-image-progress": "^1.1.1",
    "react-native-image-resizer": "^1.4.5",
    "react-native-image-slider-box": "^2.0.7",
    "react-native-lightbox": "^0.8.1",
    "react-native-linear-gradient": "^2.5.6",
    "react-native-loading-spinner-overlay": "^1.1.0",
    "react-native-maps": "^0.26.1",
    "react-native-material-dropdown": "^0.11.1",
    "react-native-md5": "^1.0.0",
    "react-native-modal": "^11.4.0",
    "react-native-modal-datetime-picker": "^7.6.0",
    "react-native-onesignal": "^3.8.1",
    "react-native-otp-textinput": "^0.0.8",
    "react-native-permissions": "^2.2.2",
    "react-native-phone-number-input": "^2.1.0",
    "react-native-popup-dialog": "^0.18.3",
    "react-native-progress": "^4.1.2",
    "react-native-qrcode-scanner": "^1.5.4",
    "react-native-qrcode-svg": "^5.3.2",
    "react-native-reanimated": "^1.13.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.4.0",
    "react-native-search-filter": "^0.1.5",
    "react-native-select-dropdown": "^1.13.0",
    "react-native-share": "^8.2.1",
    "react-native-simple-radio-button": "^2.7.4",
    "react-native-sms-retriever": "^1.1.1",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "^0.11.0",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^9.6.4",
    "react-native-swiper": "^1.6.0-rc.2",
    "react-native-tab-view": "^2.10.0",
    "react-native-textarea": "^1.0.3",
    "react-native-toast-message": "^1.3.1",
    "react-native-vector-icons": "^6.6.0",
    "react-native-version-check": "^3.4.2",
    "react-native-webview": "^11.17.2",
    "react-navigation": "^4.0.10",
    "react-navigation-stack": "^1.9.4",
    "react-navigation-tabs": "^2.5.6",
    "react-redux": "^7.1.1",
    "redux": "^4.0.4",
    "redux-logger": "^3.0.6",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "rn-range-slider": "^2.2.2",
    "run": "^1.4.0",
    "socket.io-client": "^2.3.0",
    "url": "^0.11.0",
    "url-search-params-polyfill": "^8.1.1",
    "validator": "^13.7.0"
  },
  "devDependencies": {
    "@babel/core": "7.9.0",
    "@babel/runtime": "7.9.2",
    "@babel/types": "^7.9.0",
    "@react-native-community/eslint-config": "0.0.5",
    "@types/react-test-renderer": "^16.9.2",
    "babel-jest": "24.9.0",
    "babel-plugin-transform-remove-console": "^6.9.4",
    "eslint": "6.8.0",
    "jest": "24.9.0",
    "jetifier": "^1.6.8",
    "metro-react-native-babel-preset": "0.56.4",
    "react-test-renderer": "16.9.0",
    "typescript": "^3.8.3"
  },
  "jest": {
    "preset": "react-native"
  },
  "rnpm": {
    "assets": [
      "./app/assets/fonts/"
    ]
  }
}

app.json

{
  "name": "MyApp",
  "displayName": "MyApp",
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxxxxxxxx45~48xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}

ios/Podfile

No response

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        supportLibVersion = "33.0.0"
        googlePlayServicesIidVersion = "17.0.0"
    }
    repositories {
        google()
        jcenter()
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.1.3')
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.8, 0.99.99]'
        classpath 'com.google.gms:google-services:4.3.4'
    }
}

allprojects {
    configurations.all {
        resolutionStrategy {
            force 'com.facebook.react:react-native:0.61.5' //select Version you used
        }
    }
    repositories {
        mavenLocal()
        maven {
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        maven { url 'https://maven.google.com' }

        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
    buildDir = "${rootProject.rootDir}/build/${project.name}"
}

android/app/build.gradle

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

apply plugin: "com.android.application"

apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false
]

def enableSeparateBuildPerCPUArchitecture = false

def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    dexOptions {
        javaMaxHeapSize "4g"
      }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.myapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        missingDimensionStrategy 'react-native-camera', 'general'
        versionCode 3
        versionName "2.0"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = 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 {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            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 project(':react-native-image-crop-picker')
    implementation project(':react-native-reanimated')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-linear-gradient')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation platform('com.google.firebase:firebase-bom:28.0.1')
    implementation 'androidx.work:work-runtime:2.7.1'
    implementation project(':react-native-version-check')
    implementation project(':react-native-device-info')
    implementation project(':react-native-audio')
    implementation project(':react-native-fs')
    implementation project(':react-native-sms-retriever')
    compileOnly 'com.github.pengrad:jdk9-deps:1.0'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation 'com.facebook.soloader:soloader:0.10.4+'
    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

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)

android/settings.gradle

rootProject.name = 'MyApp'
include ':react-native-image-crop-picker'
project(':react-native-image-crop-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-image-crop-picker/android')
include ':react-native-reanimated'
project(':react-native-reanimated').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-reanimated/android')
include ':react-native-gesture-handler'
project(':react-native-gesture-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-gesture-handler/android')
include ':react-native-linear-gradient'
project(':react-native-linear-gradient').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-linear-gradient/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-version-check'
project(':react-native-version-check').projectDir = new File(rootProject.projectDir,    '../node_modules/react-native-version-check/android')
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
include ':react-native-audio'
project(':react-native-audio').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-audio/android')
include ':react-native-fs'
project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')
include ':react-native-sms-retriever'
project(':react-native-sms-retriever').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sms-retriever/android')

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.myapp" xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.VIBRATE"/>

    <application
            android:name=".MainApplication"
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:icon="@mipmap/ic_myapp_launcher"
            android:allowBackup="false"
            android:usesCleartextTraffic="true"
            android:theme="@style/AppTheme"
            android:requestLegacyExternalStorage="true">
        <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@drawable/ic_stat_onesignal_default" />
        <activity
                android:name=".MainActivity"
                android:exported="true"
                android:label="@string/app_name"
                android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustResize"
                tools:node="merge"
                tools:replace="android:exported">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="myapp" android:host="menu" />
                <data android:host="myapp.page.link" android:scheme="https"/>
                <data android:host="myapp.page.link" android:scheme="http"/>
            </intent-filter>
        </activity>
        <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="true" tools:node="merge" />

        <meta-data android:name="com.onesignal.NotificationAccentColor.DEFAULT" android:value="#C31C0D" />

        <activity android:name="com.onesignal.NotificationOpenedActivityHMS" android:exported="true" tools:replace="android:exported"></activity>
        <receiver android:name="com.onesignal.GcmBroadcastReceiver" android:exported="true" tools:replace="android:exported"></receiver>
        <receiver android:name="com.onesignal.BootUpReceiver" android:exported="true" tools:replace="android:exported"></receiver>
        <receiver android:name="com.onesignal.UpgradeReceiver" android:exported="true" tools:replace="android:exported"></receiver>

        <service
            android:name="com.google.firebase.messaging.FirebaseMessagingService"
            android:exported="false" tools:replace="android:exported" >
        </service>

    </application>

</manifest>
github-actions[bot] commented 8 months ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.