Skip to content

Solving version conflicts with project.ext no longer working in 3.3 #878

Closed

Description

@NickIliev

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

Activity

  1. self-assigned this
    on Nov 9, 2017
  2. NickIliev commented on Nov 9, 2017

    @NickIliev
    Author

    @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"
    }
    
  3. self-assigned this
    on Nov 9, 2017
  4. petekanev commented on Nov 9, 2017

    @petekanev
    Contributor

    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.

  5. hettiger commented on Nov 9, 2017

    @hettiger

    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?

  6. petekanev commented on Nov 9, 2017

    @petekanev
    Contributor

    @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

  7. hettiger commented on Nov 9, 2017

    @hettiger

    @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
  8. petekanev commented on Nov 9, 2017

    @petekanev
    Contributor

    @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.

  9. hettiger commented on Nov 9, 2017

    @hettiger

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

  10. petekanev commented on Nov 9, 2017

    @petekanev
    Contributor

    @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!

  11. hettiger commented on Nov 9, 2017

    @hettiger

    @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 👍

  12. petekanev commented on Nov 13, 2017

    @petekanev
    Contributor

    Problem addressed in the 3.3.1 release of NativeScript.

  13. AnthonySmith01 commented on Nov 28, 2017

    @AnthonySmith01

    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

  14. AnthonySmith01 commented on Nov 28, 2017

    @AnthonySmith01

    Ah found my own solution just then, looks like the window path was too long. Here is a link for anyone else: #803

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions