Justin
Justin

Reputation: 18186

Using a newer Android Gradle plugin in React Native

When I try to build our Android React Native app, it generates these warnings related to Gradle:

WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.
OneSignalPlugin: WARNING: OneSignalPlugin: Downgraded 'com.android.support:33.0.0' -> 28.+ to prevent compile errors! Recommend updating your project's compileSdkVersion!
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.2.1) was tested up to compileSdk = 32

I'm not sure why it's complaining about the compileSdkVersion being updated to 33, as that's exactly what I have specified in my build.gradle file:

buildscript {
    ext {
        buildToolsVersion = "33.0.0"
        minSdkVersion = 21
        compileSdkVersion = 33
        targetSdkVersion = 33
        supportLibVersion = "33.0.0"
        castFrameworkVersion = "21.0.0"
        kotlinVersion = "1.6.0"
        ...

However, the more pressing issue is that I'm trying to upgrade the Android Gradle plugin to a newer version. In build.gradle I have:

classpath("com.android.tools.build:gradle:7.0.4")

...and in gradle-wrapper.properties I have:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip

I've tried changing build.gradle to use version 7.3.3, however then it fails to find the pom file to download.

> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.android.tools.build:gradle:7.3.3.
        Searched in the following locations:
          - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
          - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
        Required by:
            project :
      > Could not find com.android.tools.build:gradle:7.3.3.
        Searched in the following locations:
          - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
          - https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
        Required by:
            project : > project :react-native-gradle-plugin

Here is the full build log, in case it helps: https://gist.github.com/justintoth/11b462c7dbe0f51a2e78a62950e2b969

Upvotes: 3

Views: 8343

Answers (1)

Justin
Justin

Reputation: 18186

The answer is that there is a difference between the Gradle version (7.4.2 in my case) and the Android Tools Gradle version (7.3.1 in my case.) So in build.gradle I specified:

classpath("com.android.tools.build:gradle:7.3.1")

...and then in gradle-wrapper.properties I have:

distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip

This now "works", although I ran into many other build and runtime errors while upgrading to React Native 0.70.x so I'm still not there yet...

Upvotes: 1

Related Questions