Android-runtime: Solving version conflicts with project.ext no longer working in 3.3

Created on 9 Nov 2017  路  12Comments  路  Source: NativeScript/android-runtime

_From @hettiger on November 8, 2017 17:10_

Issue

In {NS} 3.2 I did something like this in my app.gradle file to have nativescript-plugin-firebase work well together with nativescript-cardview, nativescript-geolocation and nativescript-google-maps-sdk plugins:

// Add your native dependencies here:

// Uncomment to add recyclerview-v7 dependency
//dependencies {
//  compile 'com.android.support:recyclerview-v7:+'
//}

android {  
  defaultConfig {  
    generatedDensities = []
    applicationId = "org.nativescript.testns33"
    multiDexEnabled = true
  }  
  aaptOptions {  
    additionalParameters "--no-version-vectors"  
  }
  project.ext {
    googlePlayServicesVersion = "11.2.2"
    supportVersion = "26.0.0"
  }
}

def settingsGradlePath = "$projectDir/../../app/App_Resources/Android/settings.gradle";
def settingsGradleFile = new File(settingsGradlePath);
if(settingsGradleFile.exists())
{
    apply from: settingsGradleFile;
}

Unfortunately this no longer works with {NS} 3.3 because the following part no longer gets respected:

  project.ext {
    googlePlayServicesVersion = "11.2.2"
    supportVersion = "26.0.0"
  }

Proof

If you put something like this into the node_modules/..../nativescript-geolocation/.../include.gradle

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

android {
    productFlavors {
        "nativescript-geolocation" {
            dimension "nativescript-geolocation"
        }
    }
}

dependencies {
    def googlePlayServicesVersion = project.ext.googlePlayServicesVersion
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
}

You get an error like this:

FAILURE: Build failed with an exception.

* Where:
Script '~/test-ns-33/platforms/android/build/configurations/nativescript-geolocation/include.gradle' line: 19

* What went wrong:
A problem occurred evaluating script.
> Cannot get property 'googlePlayServicesVersion' on extra properties extension as it does not exist

_Copied from original issue: NativeScript/NativeScript#5049_

bug android

Most helpful comment

Problem addressed in the 3.3.1 release of NativeScript.

All 12 comments

@hettiger confirming this as a bug with the latest Android runtime (3.3.0).
The issue is not reproducible with tns-android 3.2.0

Steps to reproduce:

  • create sample project tns create issue5043 --tsc
  • add a plugin that uses Google Play Services
tns plugin add nativescript-geolocation
  • in the application app.gradle add googlePlayServicesVersion
project.ext {
    googlePlayServicesVersion = "11.2.2"
  }
  • in the plugin include.gradle use the propery
dependencies {
    def googlePlayServicesVersion = project.googlePlayServicesVersion
    compile "com.google.android.gms:play-services-location:$googlePlayServicesVersion"
}

Hey @hettiger, the user configurations which provides the global property for other plugins to interpolate from is applied after all the other configurations. This mechanism allows the user configuration to take precedence and override any other gradle rules the user would decide.

We'll let you know when the problem has been addressed.

Thank you for the update @Pip3r4o

I can imagine it breaks a lot of apps that people try to update and it's really hard for non native devs to figure out what's going on thought. Maybe there should be a notice on https://docs.nativescript.org/releases/breaking-changes until this has been fixed?

@hettiger the issue has been addressed.

Please give the fix a try by executing tns platform add android@rc which should fetch the pre-release of today's hotfix 3.3.1

Expect a patch release (3.3.1) of the android runtime later today

@Pip3r4o Thank you for the hotfix. I've successfully built with 3.3.1 removing the following part from my app.gradle file:

def settingsGradlePath = "$projectDir/../../app/App_Resources/Android/settings.gradle";
def settingsGradleFile = new File(settingsGradlePath);
if(settingsGradleFile.exists())
{
    apply from: settingsGradleFile;
}

NativeScript Sidekick adds these lines automatically to my app.gradle file.

Conclusion

  • The hotfix solves the initial problem
  • The hotfix introduces __incompatibility with NativeScript Sidekick__

@hettiger I've not tried the changes with Sidekick, I'll test further with Sidekick before pushing the patch release to ensure there are no incompatibilities.

@Pip3r4o That's great news, thank you. If you want me to test it again let me know once another RC is available.

@hettiger we reverted the app.gradle application logic altogether to match the pre-3.3.0 behavior. Please give the android@rc another try. Thank you!

@Pip3r4o awesome, I can now confirm that it is working with or without the additions from Sidekick. Thank you, looking forward to be installing the patch 馃憤

Problem addressed in the 3.3.1 release of NativeScript.

Hi @Pip3r4o , thanks for the great work on this.

Although I received a new error when using android@rc, any ideas?

Error: Failed to crunch file C:\project\platforms\android\build\intermediates\exploded-aar\com.google.android.gms\play-services-base\11.6.2\res\drawable-hdpi-v4\common_google_signin_btn_icon_dark_normal_background.9.png into C:\project\platforms\android\build\intermediates\res\merged\F0F1F2F3\debug\drawable-hdpi-v4\common_google_signin_btn_icon_dark_normal_background.9.png

Ah found my own solution just then, looks like the window path was too long. Here is a link for anyone else: https://github.com/NativeScript/android-runtime/issues/803

Was this page helpful?
0 / 5 - 0 ratings