Reputation: 620
I am trying to build a simple android project on the command line using
android create project
I am following this tutorial, and using android-sdk tools version 25.2.5 which still includes the above command. However, my gradle version is 4.8.1 and java 10.0.1.
First, I cd into my project folder and use the android command to create a project:
android create project -p . -a MainActivity -k com.test.firstapp -t "android-22" -g -v 2.3.0
This gives me a project frame. I chose the android gradle plugin version 2.3.0 based on this web page, hoping it would support all newer versions of gradle as well.
Then I try to build the project with
./gradlew build
and get my first error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '10.0.1'.
So I reckoned there must be a mismatch with the gradle version and the gradle plugin version I am using because gradle 4.8.1 should definitely support java 10.0.1. I then went and looked at my build.gradle file in the project directory and changed the android plugin version to 3.1.0, as follows:
classpath 'com.android.tools.build:gradle:3.1.0'
also adding google() to the repositories. I still got the same java version error. Now, I had a look at gradle/wrapper/gradle-wrapper.properties and saw that the distributionUrl was for gradle 1.12, so I changed it to my actual version:
distributionUrl=http\://services.gradle.org/distributions/gradle-4.8.1-all.zip
After changing the gradle version in the wrapper, I call:
gradle wrapper --gradle-version 4.8.1
as advised here. Running this, I first get a warning and and error:
Configure project :
WARNING: The specified Android SDK Build Tools version (22.0.1)
is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.0.
Android SDK Build Tools 27.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '22.0.1'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
File /home/user/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 27.0.3 in /opt/android-sdk/licenses
License for package Android SDK Build-Tools 27.0.3 accepted.
Preparing "Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)".
Warning: Failed to read or create install properties file.
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.
FAILURE: Build failed with an exception.
* Where:
Build file '/home/user/dev/android/firstapp/build.gradle' line: 18
* What went wrong:
A problem occurred evaluating root project 'firstapp'.
> Could not find method runProguard() for arguments [false] on BuildType_Decorated{name=release, debuggable=false, testCoverageEnabled=false, jniDebuggable=false, pseudoLocalesEnabled=false, renderscriptDebuggable=false, renderscriptOptimLevel=3, minifyEnabled=false, zipAlignEnabled=true, signingConfig=null, embedMicroApp=true, mBuildConfigFields={}, mResValues={}, mProguardFiles=[], mConsumerProguardFiles=[], mManifestPlaceholders={}} of type com.android.build.gradle.internal.dsl.BuildType.
I'm sure it's a mismatch of versions but could someone point out what the right combination is if I want to keep working with android-sdk tools 25.2.5?
I'm doing this on Ubuntu 16.04.
Thanks.
Upvotes: 1
Views: 1676
Reputation: 620
In the end, the combination that works for me was the following:
android sdk tools 25.2.5
android build tools 26.0.2
platform-tools 28.0.0 (uncritical in any case...)
java 8 (indeed had to downgrade)
gradle 4.8.1
android gradle plugin 3.0.1
With this combination I was able to create a project using 'android create project' and build with './gradlew build':
> android create project -p . -a MainActivity -k com.test.firstapp -t "android-22" -g -v 3.0.1
> Created directory ....
The android tool still creates some deprecated input into build.gradle, such as proguard instead of minifyEnabled, and leaves out some repositories (google(), jcenter()) that I need to find the newer gradle plugin version, among other things. Also, the gradle-wrapper.properties sill contain an outdated gradle version url but that can be changed as shown in my original question. I'm a lot closer to automating project creation from the command line than before even if it's not perfect.
Upvotes: 1