Inside build.gradle I am trying to do something like this
task wrapper(type: Wrapper){
if(BUILD_API.toInteger() >= 30 && BUILD_USE_11.toBoolean()) // Basically as is mentioned is Build >= 30 and want to use Java 11+
{
gradleVersion = ‘7.5’
distributionType = Wrapper.DistributionType.ALL
// distributionUrl=‘https\://services.gradle.org/distributions/gradle-7.5-all.zip’
}
else
{
gradleVersion = ‘6.7.1’
distributionType = Wrapper.DistributionType.ALL
// distributionUrl=‘https\://services.gradle.org/distributions/gradle-6.7.1-all.zip’
}
}
I want to keep some old devs running, but I get this error.
Cannot add task ‘wrapper’ as a task with that name already exists.
then using your literature
https://docs.gradle.org/7.3/userguide/gradle_wrapper.html
Tried as:
tasks.named(‘wrapper’) {
if(BUILD_API.toInteger() >= 30 && BUILD_USE_11.toBoolean())
{
gradleVersion = ‘7.5’
distributionType = Wrapper.DistributionType.ALL
// distributionUrl=‘https\://services.gradle.org/distributions/gradle-7.5-all.zip’
}
else
{
gradleVersion = ‘6.7.1’
distributionType = Wrapper.DistributionType.ALL
// distributionUrl=‘https\://services.gradle.org/distributions/gradle-6.7.1-all.zip’
}
}
and i get this error
problem occurred evaluating project ‘:app’.
Failed to apply plugin ‘com.android.internal.application’.
Failed to create service ‘com.android.build.gradle.options.ProjectOptionService_380a0b53-dfb7-4b5e-9298-105695e17a43’.
Could not create an instance of type com.android.build.gradle.options.ProjectOptionService.
Cannot obtain value from provider of Gradle property ‘android.testInstrumentationRunnerArguments.package’ at configuration time.
Use a provider returned by ‘forUseAtConfigurationTime()’ instead.
I guess because is not getting the proper android tools
Even though in both cases in build.gradle inside dependencies for android.
(NOTE same error testing by commenting version/type and using final distributionUrl)
buildscript {
repositories {
google()
mavenCentral()
maven { url "https://maven.google.com" }
//AllBuildRepos
}
dependencies {
if(BUILD_API.toInteger() >= 30 && BUILD_USE_11.toBoolean())
{
classpath 'com.android.tools.build:gradle:7.4.0'
}
else
{
classpath 'com.android.tools.build:gradle:4.2.0'
}
}
}
note if I do the change manually in gradle-wrapper.properties, everything work as expected
and the final reason in build.gradle.app
compileOptions {
if(BUILD_API.toInteger() >= 30 && BUILD_USE_11.toBoolean())
{
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
else
{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Is this possible?, what I missed here
Thanks in advance