React Native and Gradle

What is Gradle ?

In very simple terms Gradle, as the name might suggest, is a build platform for your App. So what ? Well just like everything in React-Native it is version specific and when you create your APP you’ll get the default ‘old’ version Gradle build style. When you open your new App with Android Studio you do get prompted to upgrade – Don’t for now or when/if you do…..

Old vs New

For most APPs this should and will be very much behind the scenes – Thank God, but a few add-ons will require that you use gradle-4.4-all.zip, which in very simple terms has changed some names specifically the compile option used in build.gradle.

Rather than explain all this just go to https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#apply_plugin and there’s a video too!

Quick Recap

You may recall that in the opening post [please read] I said DO NOT upgrade Gradle and this is simply because compile() is now implementation() – and if you do accept an upgrade then you’ll have to change your build.gradle file. NOT really the first thing you want to being doing for your HelloWorld ! App. Android Studio [to be fair] just warns you on this [2018].

There is a lot more to this upgrade than a directive-name change, as explained in the above link, but unless you are using some specific add-ons [e.g. Maps] then I would stick to the Old Gradle, until React changes their default android/app/build.gradle file to the new version!

When/If you do upgrade:

Make sure your android/build.gradle file looks like this [the Google changes] and that goggle() is FIRST in the list:

// google() must be first in the list
buildscript {
      repositories {
            google()
            jcenter()
      }
      dependencies {
            classpath 'com.android.tools.build:gradle:3.1.0'
      }
}

allprojects {
      repositories {
            google()
            mavenLocal()
            jcenter()
            maven {
                  url "https://maven.google.com"
            }
      }
}

After this, I would then re-open your App as an existing project in Android Studio [possibly removing any old project] and let Android Studio do its stuff, which will be to upload anything which is missing and amend your build.grade file with some version numbers.

Leave a reply:

Your email address will not be published.

Site Footer