I have a plugin which needs the very last support library.
Consequently I set up include.gradle with the correct version. You can see it here
However when I build through my app it fails because the plugin is built with the wrong versions.
If I print the corresponding gradle call:
/gradlew -p /myappfolder/platforms/tempPlugin/nativescript_material_components assembleRelease -PcompileSdk=android-27 -PbuildToolsVersion=27.0.3 -PsupportVersion=26.0.0-alpha1
The build.gradle within the temp folder does not take into account the targetSDk or compileSDKVersion that I have set-up in include.gradle. Only the dependencies are correct.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
apply plugin: 'com.android.library'
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 24 }
def computeBuildToolsVersion = { ->
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "27.0.3"
}
android {
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()
defaultConfig {
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
dependencies {
def supportVer = "27.0.1"
if (project.hasProperty("supportVersion")) {
supportVer = supportVersion
}
compileOnly "com.android.support:support-v4:$supportVer"
compileOnly "com.android.support:appcompat-v7:$supportVer"
}
dependencies {
compile "com.android.support:appcompat-v7:28+"
compile 'com.android.support:design:28+'
}
That build.gradle should have targetSDKVersion, compileSDKVersion, buildToolsVersion setup in that order:
BTW in the default app `build.gradle``` the applying
The order should be
setAppIdentifier()
applyPluginGradleConfigurations()
applyAppGradleConfiguration()
User app configuration should always overrule.
Right now I can't seem to find a way to compile my app with that module. Any help would be appreciated
Thanks
BTW: It would be very useful to always print versions actually used by gradle. In my dev I simply did it by printing within the gradle build file.
Hey @farfromrefug ,
Thanks for reporting this issue. I can confirm this behavior is not expected. The reason is some legacy code in CLI that tries to find your local version of the support library and pass it to Gradle build. This was required in the past, but since some time, this is no longer required, as the versions are not copied locally, but from the google repository as stated here: The support libraries are now available through Google's Maven repository. We no longer support downloading the libraries through the SDK Manager, and that functionality will be removed soon..
We'll adjust CLI's behavior according to these changes and this will allow you to define your own version of the library.
Thanks again for reporting this.
From CLI version 5.0.0-2018-09-25-12300, CLI no longer requires local installation of Android Support Repository and no longer passes it to Gradle build. This means, that the version of the support library that will be used is specified in build.gradle file (inside platforms dir). Users can overwrite it in app.gradle by adding the following code:
project.ext.supportVersion = "27.0.2"
Existing applications that are using older runtime (not 5.0.0 one), but are built with CLI 5.0.0, may experience some changes - until now CLI was always passing parameter to gradle -PsupportVersion=26.0.0-alpha1. As CLI no longer passes this version, the default one from build.gradle will be used (for example 27.0.1). In case you want to use the old version in your application, add the following in your app.gradle:
project.ext.supportVersion = "26.0.0-alpha1"
@rosen-vladimirov great! So it can be set too for a plugin?
I my plugin require 28+ I can put project.ext.supportVersion = "28.0.0" in my plugin platforms/android/build.gradle?
Which can be overloaded by the app platforms/android/app.gradle?
Hey @farfromrefug ,
We are still testing the behavior and issues that might occur with the current case. But yes, you should be able to use it in a plugin. You can also set the following in your app.gradle (at the root fo the file):
project.ext.supportVersion = 28.0.0
In case you want to set it from a plugin, I recommend you to put something like this in your include.gradle:
def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "28.0.0"
// You can also add some check here that the `supportVersion` is at least 28.0.0
dependencies {
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:recyclerview-v7:$supportVersion"
}
Using the code above will allow the application author to control the version from a single place (project's app.gradle for example).
Set the project.ext properties in your app.gradle like so:
project.ext.supportVersion = '27.1.1'
project.ext.buildToolsVersion = '28.0.3'
project.ext.compileSdk = 28
project.ext.targetSdk = 28
android {
defaultConfig {
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
app/App_Resources/Android/gradle.properties and plugin gradle.properties are ignoredapp/App_Resources/Android/app.gradle config options are ignored:// does not work :(
android {
buildToolsVersion '28.0.3'
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
}
}
@farfromrefug @NickIliev @rosen-vladimirov
@rosen-vladimirov This still won't work for plugins.
The issue is with plugin build within app.
The "tempPlugin" created has a build.gradle which ignore the
def supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "28.0.0"
For a plugin include.gradle like this:
def supportVersion = project.ext.supportVersion = project.hasProperty("supportVersion") ? project.supportVersion : "28.0.0"
dependencies {
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
}
the tempPlugin build.gradle is this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
jcenter()
}
}
apply plugin: 'com.android.library'
def computeCompileSdkVersion = { -> project.hasProperty("compileSdk") ? compileSdk : 24 }
def computeBuildToolsVersion = { ->
project.hasProperty("buildToolsVersion") ? buildToolsVersion : "27.0.3"
}
android {
compileSdkVersion computeCompileSdkVersion()
buildToolsVersion computeBuildToolsVersion()
defaultConfig {
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
}
dependencies {
def supportVer = "27.0.1"
if (project.hasProperty("supportVersion")) {
supportVer = supportVersion
}
compileOnly "com.android.support:support-v4:$supportVer"
compileOnly "com.android.support:appcompat-v7:$supportVer"
}
dependencies {
compile "com.android.support:appcompat-v7:$supportVersion"
compile "com.android.support:design:$supportVersion"
}
In my case it won't compile
/Volumes/data/mguillon/.gradle/caches/transforms-1/files-1.1/appcompat-v7-26.0.0-alpha1.aar/6d00e62d8dee63a3028d01e3add9e07e/res/values/values.xml:353:5-359:13: AAPT: error: style attribute 'attr/materialButtonStyle (aka org.nativescript.nativescript_material_components:attr/materialButtonStyle)' not found.
BTW as you can see it actually uses 26.0.0-alpha1 so somewhere supportVersion is set to 26.0.0-alpha1
So 2 errors:
supportVersion is not propagatedapp.gradle: project.ext.supportVersion = '28.0.0'@farfromrefug You can try adding a file named before-plugins.gradle https://github.com/NativeScript/template-blank-ts/commit/28cad07610c71be11221bf904f04c6c5a61ecc32
@roblav96 thanks i will do for sure But this won't fix the tempPlugin build like described in my last comment i think. Will try though.
Thanks
@rosen-vladimirov as i mentioned there is still an issue with plugins compilation.
right now here:
https://github.com/NativeScript/nativescript-cli/blob/e3ae1df2520e810df82c4ce733a20031f745c971/lib/services/android-plugin-build-service.ts#L285
Only the template gradle files are used. Consequently there is no way to override supportVersion, compileSdk, buildToolsVersion
Even thow in the template files you query project properties there is no way to set them.
This is fixed in latest cli versions