Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛] Android build failed #699

Open
1 task done
wbalogun opened this issue Jan 23, 2025 · 1 comment
Open
1 task done

[🐛] Android build failed #699

wbalogun opened this issue Jan 23, 2025 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@wbalogun
Copy link

What happened?

Android build failed with the error blow:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-google-mobile-ads:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

Image

Platforms

Only on Android

React Native Info

Node:
    version: 20.10.0
    path: ~/.nvm/versions/node/v20.10.0/bin/node
  Yarn: Not Found
  npm:
    version: 10.2.3
    path: ~/.nvm/versions/node/v20.10.0/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.2
      - iOS 18.2
      - macOS 15.2
      - tvOS 18.2
      - visionOS 2.2
      - watchOS 11.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2021.3 AI-213.7172.25.2113.9123335
  Xcode:
    version: 16.2/16C5032a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.17
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /Users/xxx/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.12
    wanted: 0.72.12
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Are your using Typescript?

  • My project is using Typescript

package.json

{
...
"dependencies": {
    ...
    "react-native-google-mobile-ads": "14.8.1",
    "react-native": "0.72.12",
    "react": "18.2.0",
    ...
}
...
}

app.json

"react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxx~yyy",
    "ios_app_id": "ca-app-pub-xxx~yyy",
    "delay_app_measurement_init": false,
    "optimize_initialization": true,
    "optimize_ad_loading": true,
    "user_tracking_usage_description": "This identifier will be used to deliver personalized ads to you.",
    "sk_ad_network_items": [
      "cstr6suwn9.skadnetwork",
      "4fzdc2evr5.skadnetwork",
      "2fnua5tdw4.skadnetwork",
      "ydx93a7ass.skadnetwork",
      "p78axxw29g.skadnetwork",
      "v72qych5uu.skadnetwork",
      "ludvb6z3bs.skadnetwork",
      "cp8zw746q7.skadnetwork",
      "3sh42y64q3.skadnetwork",
      "c6k4g5qg8m.skadnetwork",
      "s39g8k73mm.skadnetwork",
      "3qy4746246.skadnetwork",
      "hs6bdukanm.skadnetwork",
      "mlmmfzh3r3.skadnetwork",
      "v4nxqhlyqp.skadnetwork",
      "wzmmz9fp6w.skadnetwork",
      "su67r6k2v3.skadnetwork",
      "yclnxrl5pm.skadnetwork",
      "7ug5zh24hu.skadnetwork",
      "gta9lk7p23.skadnetwork",
      "vutu7akeur.skadnetwork",
      "y5ghdn5j9k.skadnetwork",
      "v9wttpbfk9.skadnetwork",
      "n38lu8286q.skadnetwork",
      "47vhws6wlr.skadnetwork",
      "kbd757ywx3.skadnetwork",
      "9t245vhmpl.skadnetwork",
      "a2p9lx4jpn.skadnetwork",
      "22mmun2rn5.skadnetwork",
      "4468km3ulz.skadnetwork",
      "2u9pt9hc89.skadnetwork",
      "8s468mfl3y.skadnetwork",
      "ppxm28t8ap.skadnetwork",
      "uw77j35x4d.skadnetwork",
      "pwa73g5rt2.skadnetwork",
      "578prtvx9j.skadnetwork",
      "4dzt52r2t5.skadnetwork",
      "tl55sbb4fm.skadnetwork",
      "e5fvkxwrpn.skadnetwork",
      "8c4e2ghe7u.skadnetwork",
      "3rd42ekr43.skadnetwork",
      "3qcr597p9d.skadnetwork"
    ]
  }

ios/Podfile

android/build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
// https://github.com/DylanVann/react-native-fast-image/blob/main/docs/app-glide-module.md
project.ext {
    excludeAppGlideModule = true
}

buildscript {
    ext {
        compileSdkVersion = findProperty("android.compileSdkVersion") as Integer
        targetSdkVersion = findProperty("android.targetSdkVersion") as Integer
        minSdkVersion = findProperty("android.minSdkVersion") as Integer

        buildToolsVersion = findProperty("android.buildToolsVersion") as String
        supportLibVersion = findProperty("android.supportLibVersion") as String
        ndkVersion = findProperty("android.ndkVersion") as String
        kotlinVersion = '1.6.20'
        googlePlayServicesVersion = "17.0.0"
        googlePlayServicesLocationVersion = "21.0.1"  // Or higher.
    }

    repositories {
        jcenter()
        google()
    }

    dependencies {
      classpath("com.android.tools.build:gradle")
      classpath("com.facebook.react:react-native-gradle-plugin")
      classpath('de.undercouch:gradle-download-task:5.0.1')
      classpath 'com.google.gms:google-services:4.3.14'
      classpath "com.bugsnag:bugsnag-android-gradle-plugin:7.+"
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

    // Fixes this issue  -> In order to compile Java 9+ source, please set compileSdkVersion to 30 or above
    // Sets compileSdkVersion for each subproject to the main version
    subprojects { subproject ->
        afterEvaluate{
            if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
                android {
                    compileSdkVersion rootProject.ext.compileSdkVersion
                    buildToolsVersion rootProject.ext.buildToolsVersion
                }
            }
        }
    }
}

allprojects {
    repositories {
        mavenLocal()

        google()
        jcenter()
        // Custom

       
    }
}

android/app/build.gradle

apply plugin: "com.android.application"
apply plugin: "com.facebook.react"

import com.android.build.OutputFile

/**
 * This is the configuration block to customize your React Native Android app.
 * By default you don't need to apply any configuration, just uncomment the lines you need.
 */

react {
//    bundleInInternalTest = true
//    bundleInStaging = true
    /* Folders */
    //   The root of your project, i.e. where "package.json" lives. Default is '..'
    // root = file("../")
    //   The folder where the react-native NPM package is. Default is ../node_modules/react-native
    // reactNativeDir = file("../node-modules/react-native")
    //   The folder where the react-native Codegen package is. Default is ../node_modules/react-native-codegen
    // codegenDir = file("../node-modules/react-native-codegen")
    //   The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
    // cliFile = file("../node_modules/react-native/cli.js")
    /* Variants */
    //   The list of variants to that are debuggable. For those we're going to
    //   skip the bundling of the JS bundle and the assets. By default is just 'debug'.
    //   If you add flavors like lite, prod, etc. you'll have to list your debuggableVariants.
    // debuggableVariants = ["liteDebug", "prodDebug"]
    /* Bundling */
    //   A list containing the node command and its flags. Default is just 'node'.
    // nodeExecutableAndArgs = ["node"]
    //
    //   The command to run when bundling. By default is 'bundle'
    // bundleCommand = "ram-bundle"
    //
    //   The path to the CLI configuration file. Default is empty.
    // bundleConfig = file(../rn-cli.config.js)
    //
    //   The name of the generated asset file containing your JS bundle
    // bundleAssetName = "MyApplication.android.bundle"
    //
    //   The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
    entryFile = file("../../index.ts")
    //
    //   A list of extra flags to pass to the 'bundle' commands.
    //   See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
    // extraPackagerArgs = []
    /* Hermes Commands */
    //   The hermes compiler command to run. By default it is 'hermesc'
    // hermesCommand = "$rootDir/my-custom-hermesc/bin/hermesc"
    //
    //   The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
    // hermesFlags = ["-O", "-output-source-map"]
}

/**
 * Set this to true to create four separate APKs instead of one,
 * one for each native architecture. This is useful if you don't
 * use App Bundles (https://developer.android.com/guide/app-bundle/)
 * and want to have separate APKs to upload to the Play Store.
 */
def enableSeparateBuildPerCPUArchitecture = true

apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"

/**
 * Set this to true to Run Proguard on Release builds to minify the Java bytecode.
 */
def enableProguardInReleaseBuilds = false

/**
 * The preferred build flavor of JavaScriptCore (JSC)
 *
 * 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:+'

/**
 * Private function to get the list of Native Architectures you want to build.
 * This reads the value from reactNativeArchitectures in your gradle.properties
 * file and works together with the --active-arch-only flag of react-native run-android.
 */
def reactNativeArchitectures() {
    def value = project.getProperties().get("reactNativeArchitectures")
    return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

android {
    ndkVersion rootProject.ext.ndkVersion
    compileSdkVersion rootProject.findProperty("android.compileSdkVersion") as Integer
    buildToolsVersion rootProject.findProperty("android.buildToolsVersion") as String

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    /*
      Required to enable us to build the bundled
      Facetec lib from react-native-facetec.
      Solution found here: https://stackoverflow.com/a/58602329
    */
    packagingOptions {
      pickFirst '**/*.so'
      exclude 'META-INF/androidx.*'
      exclude 'androidx.*'
      exclude 'META-INF/DEPENDENCIES'
    }

    defaultConfig {
        manifestPlaceholders = [
           // ...
        ]
        minSdkVersion rootProject.findProperty("android.minSdkVersion") as Integer
        targetSdkVersion rootProject.findProperty("android.targetSdkVersion") as Integer

        applicationId findProperty("android.applicationId") as String
        versionCode findProperty("android.versionCode") as Integer
        versionName findProperty("android.versionName") as String

        missingDimensionStrategy 'react-native-camera', 'general'

        multiDexEnabled true
    }
    signingConfigs {
        release {
           ...
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include (*reactNativeArchitectures())
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }

    bundle {
        density.enableSplit = true
        abi.enableSplit = true
        language.enableSplit = false
    }

    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) * 1 + defaultConfig.versionCode
            }
        }
    }
}

dependencies {
    // The version of react-native is set by the React Native Gradle Plugin
    implementation("com.facebook.react:react-android")

    implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.0.0")

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

    // Custom
    implementation 'com.android.support:multidex:1.0.3'
    implementation "androidx.multidex:multidex:2.0.1"

    // Android 4.X needs this else there is an OKHTTP Class
    // https://github.com/square/okhttp/issues/4622#issuecomment-588261353
    implementation("com.squareup.retrofit2:retrofit:2.7.1")
    implementation("com.squareup.okhttp3:okhttp:3.12.8")
    implementation "com.squareup.okhttp3:logging-interceptor:3.12.8"

    implementation ('com.google.android.gms:play-services-vision:20.1.3')
    implementation ('com.google.android.gms:play-services-vision-common:19.1.3')
    implementation "com.google.android.gms:play-services-base:18.2.0"
    implementation "com.google.android.gms:play-services-ads:21.0.0"
    implementation 'com.google.android.gms:play-services-location:21.0.1'

}

configurations.all {
   resolutionStrategy.force 'com.android.support:support-v4:26.1.0' // old dependencies version;
   resolutionStrategy.force 'androidx.appcompat:appcompat:1.3.1'
   resolutionStrategy.force 'com.google.android.material:material:1.6.0'
   resolutionStrategy {
     eachDependency { DependencyResolveDetails details ->
       // ...
     }
   }
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

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


bugsnag {
    uploadReactNativeMappings = true
}

android/settings.gradle

rootProject.name = 'AppName'

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'

includeBuild('../node_modules/@react-native/gradle-plugin')

AndroidManifest.xml

@wbalogun wbalogun added the help wanted Extra attention is needed label Jan 23, 2025
@wbalogun
Copy link
Author

I think this is related to the incompatibility of the Reactnative and react-native-google-mobile-ads versions although it works on iOS.

PS: I updated the Kotlin version but got an error related to incompatible method signatures in the React Native UI Manager classes that the ads library is trying to use.

I see there's an existing discussion around detailing supported versions #688

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant