Sync ends with BUILD SUCCESSFUL but Make Project FAILS - android-studio

All SO post on this subject (except for an unanswered one) describe the exact opposite situation: Build successful but Sync fails.
My situation is that I installed Android Studio for the first time (2021.3.1.17) and successfully imported an old (but working) Eclipse/ADT project of mine: Sync completes successfully, albeit with several warnings:
> Task :prepareKotlinBuildScriptModel UP-TO-DATE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1s
It also warns about the Java version:
Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
Your current JDK is located in C:\Program Files\Java\jdk1.8.0_341\jre
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
Gradle settings
But when I try to Build > Make Project, it surprisingly ends with an ERROR:
Build file 'C:\Users\WebViewer\StudioProjects\MyApp\billing\build.gradle' line: 1
A problem occurred evaluating project ':billing'.
> Failed to apply plugin 'com.android.internal.library'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
Your current JDK is located in C:\Program Files\Java\jdk1.8.0_341\jre
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
I understand the warnings (definitely good ones, prompting to update to current versions, and I eliminated the Java version one via File > Settings > Build Tools > Gradle) but... if Sync ends successfully, why would Make Project fail completely?
As a newcomer to Android Studio (IntelliJ + Gradle), I am confused by this discrepancy. Could someone please shed light on the essential difference between Sync, Make Project and Rebuild Project?

Related

Could not find com.android.tools.build:gradle:7.5.1

So I was building out a test APK in Android Studio tonight that had to be signed. It failed and said my Gradle was out of date. So I upgraded my gradle from 7.3.3 to the newest 7.5.1
I changed the wrapper setting to distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
and then I changed my build.gradle dependency to classpath 'com.android.tools.build:gradle:7.5.1'
Note that after doing the changes, and restarting Android Studio, it did upgrade the version in the app directory.
Here's the error getting thrown below:
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.5.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
Required by:
project :
Note that this was a project from a client, and I did not write this originally. These dependencies were in place, but fairly recent, and the app would build fine with it using 7.3.3. However it wouldn't let me sign my app.
I suppose I could use some wisdom on both of these issues. What I'm going to do is go back to version 7.3.3, build the signed APK again, and copy that exact error to report back here with. It was a gradle version error.
For any any Flutter noobs like myself passing through, this error occured because the Android Tools Plugin version DOES NOT match the Gradle Version:
https://developer.android.com/studio/releases/gradle-plugin#groovy
They match up just vaguely enough in number, that you would think that my line com.android.tools.build:gradle:7.5.1. uses gradle 7.5.1, but instead, Android Tools for Gradle is actually a separate entity, and at 7.3.3 as of typing this reply.
So you CAN set your Gradle to the newest version somewhere else in your project, but it has to match the compatible Android Tools version, which is set here. Its silly and confusing at first, and can easily trip up newcomers. Hopefully the versions diverge enough, or the code syntax changes for some better clarity, but as of now, this is it.

Github actions not picking up changes to build files in non-master branches

When building my android project via a github action, it always fails when the server hosting the action updates it's NDK plugin versions. This requires me to update my versions as well. However, it never seems to be simple.
For example, in a recent update I just made I noticed the NDK version was behind the server. So I downloaded the new version it's using to my local machine and updated the build files (including the local NDK path). After ensuring it builds fine on my local machine, I push to my branch. However, the server still thinks it's trying to build on the old version and fails the build (even though I told the gradle script to use the new version.).
I can successfully make this update on master, is there some reason actions/checkout#v2 doesn't recognize build file updates to non-master branches?
Welcome to Gradle 6.1.1!
Here are the highlights of this release:
- Reusable dependency cache
- Configurable compilation order between Groovy/Kotlin/Java/Scala
- New sample projects in Gradle's documentation
For more details see https://docs.gradle.org/6.1.1/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
> Configure project :app
WARNING: Support for ANDROID_NDK_HOME is deprecated and will be removed in the future. Use android.ndkVersion in build.gradle instead.
Support for ANDROID_NDK_HOME is deprecated and will be removed in the future. Use android.ndkVersion in build.gradle instead.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> No version of NDK matched the requested version 21.3.6528147. Versions available locally: 21.4.7075529, 21.4.7075529, 21.4.7075529, 22.1.7171670
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 24s
Error: Process completed with exit code 1.

Can not create workspace for Liferay 7.2-rc2

I am trying to create a workspace for 7.2-rc2 but fail to do so.
I created a normal workspace for 7.1 in Liferay Developer Studio (version 3.5.0) since there is no support for 7.2 yet. To test if I can run code correctly I created a new mvc-portlet in Developer Studio.
I then set liferay.workspace.target.platform.version=7.2.0 in gradle.properties. Gradle is not able to build my module:
15:16:04: Executing task 'deploy'...
Task :wrapper
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':modules:test:buildCSS'.
Could not resolve all dependencies for configuration ':modules:test:detachedConfiguration1'.
Could not find com.liferay.portal:release.portal.bom:7.2.0.
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
Required by:
project :modules:test
Could not find com.liferay.portal:release.portal.bom.compile.only:7.2.0.
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom.compile.only/7.2.0/release.portal.bom.compile.only-7.2.0.pom
https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom.compile.only/7.2.0/release.portal.bom.compile.only-7.2.0.pom
https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom.compile.only/7.2.0/release.portal.bom.compile.only-7.2.0.pom
https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom.compile.only/7.2.0/release.portal.bom.compile.only-7.2.0.pom
Required by:
project :modules:test
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 2s
Could not find com.liferay.portal:release.portal.bom:7.2.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
- https://repo.maven.apache.org/maven2/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
- https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
- https://repository-cdn.liferay.com/nexus/content/groups/public/com/liferay/portal/release.portal.bom/7.2.0/release.portal.bom-7.2.0.pom
Required by:
project :modules:test
15:16:07: Task execution finished 'deploy'.
I do not think the deprecation warning is at fault.
Which settings do I actually have to set to get all the necessary dependencies for 7.2?
It seems that 7.2.0-rc2 or rc3 have not been uploaded into the apache maven central repository yet. I'm also looking for a maven repository that has these artifacts.
By updating existing eclipse, you can build 7.2 plugin. Use below URL from liferay to update eclipse.
Install Liferay IDE

WSL gradle pre-pending current directory to Android SDK path

I have set the terminal on Android Studio to use WSL, specifically the Ubuntu one. Running builds from the IDE provided buttons works fine for my project. I decided to start using the terminal more and would prefer to run the builds from there, so I tried running
./gradlew tasks
at the root of the project to test out the Gradle I had installed with sdkman in WSL, but I get the following error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> The SDK directory '/mnt/c/Users/Henry-PC/Desktop/DJ-Cloud/C:\Users\Henry-PC\AppData\Local\Android\Sdk' does not exist.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Any ideas as to what is wrong with?
Just had this issue myself, I had a local.properties file that specified an incorrect directory.
After removing it entirely gradle is able to locate the Android SDK using the exported ANDROID_HOME environment variable

How to run gradle from the command line for Android Studio when versions mismatch?

I've got an Android Studio project and have been building it just using Build/Rebuild Project - and it builds fine.
However I'm making additions to the build.gradle file and am having an issue using AS as often the output in the Gradle Console within AS just vanishes. This means if I've made a mistake with the build.gradle additions I can't see what the problem is.
So I thought I'd run things from the command line. So I just type 'gradle' from my mac's terminal window but I get this:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Gradle version 2.2 is required. Current version is 2.10. If using the gradle wrapper, try editing the distributionUrl in /Users/Cequint/Desktop/CityIDGradle/android/CityID/gradle/wrapper/gradle-wrapper.properties to grade-2.2-all.zip
The gradle-wrapper.properties file in AS contains this:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
Yet if I type 'gradle -version' from the command line it shows I have Gradle 2.10 installed.
I tried changing the cradle-wrapper.properties file in AS to contain grade-2.2-all.zip as it said in the error message, but it made no difference.
I also tried changing it to be grade-2.10-all.zip but its still the same error message.
So the question is:
1) what can I update in the AS gradle files to build from the command line?
2) If I have a different version of gradle downloaded onto the mac, than got installed with AS. How can I download the version with AS to be the same i.e. to be v2.10?
When you run gradle from the command line, it invokes gradle from your system path, which apparently is gradle 2.10
When you add a wrapper section to your gradle.build file, as is the case with Android Studio projects, you will see a gradlew.bat and a gradlew shell script in the project root folder. These scripts will invoke (and download if required) the version of gradle defined in your wrapper section.
TL;DR: Run ./gradlew instead of gradle

Resources