Trouble getting gradle project building in Intellij: Task 'compileJava' is ambiguous - android

I am attempting to get
https://github.com/KodeinKoders/Playground-Demo-Crypto (commit 2a9b2b9)
Repository to build.
After doing some updates of tooling MacOS & XCode. And addition of the following override to gradle build file:
tasks.getByName<org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest>("iosX64Test") {
deviceId = "iPhone 14"
}
I am able to build within command line use
gradle build
On
MacOS: 13.2
XCode: 14.2
However, when I run build within IntelliJ. I get the following error:
Task 'compileJava' is ambiguous in root project 'DemoCrypto'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac', 'compileDebugUnitTestJavaWithJavac', 'compileReleaseJavaWithJavac', 'compileReleaseUnitTestJavaWithJavac'.
The IntelliJ notifications show:
Executing tasks: [:compileDebugSources, :compileDebugUnitTestSources, :compileDebugAndroidTestSources, :compileJava, :testClasses] in project /usr/local/workplace/sandbox-kotlin-thorg/Playground-Demo-Crypto
Prior to build failure.
I am new to gradle. I don't know where this list of tasks that intellij chooses to use for build is coming from? I am also confused by fact that running:
grep -r "compileDebugSources" .
From within the project root leads to 0 matches.
So the questions are:
How does IntelliJ choose to use that particular list of tasks to for its build. Given that compileDebugSources doesnt even exist in the project.
Advice on getting the build to work in IntelliJ?

Related

Configure Bamboo for Android Gradle based Project

I am trying to setup Bamboo for my Gradle build system based Android Project.
I have done the following setup on Bamboo.I'm done with rest of all setup upto project repository path.
I want to run the following tasks using gradlew for android
clean assembleDebug LintDebug
For that I have created new task called Gradle Wrapper.
Below is the Gradle Wrapper Configuration
When I am executing gradle wrapper task, I am getting the following error.
Caused by: java.lang.IllegalStateException: Cannot find executable 'D:\AndroidDemo\gradle-2.10\bin\gradlew.bat'
Note :- Standalone Gradle is working fine on local machine with all the tasks(clean assembleDebug LintDebug)
Gradle_Home = D:\AndroidDemo\gradle-2.10\bin(Local machine)
Can anyone suggest a solution for the same?
I also had some initial difficulties to set up Bamboo to build an Android project using Gradle.
First of all, make sure that you have the Gradle wrapper (gradlew) in your repo. (Seemingly that's the situation in your case). It seems to me, however the Gradle wrapper ignores the system default Gradle distribution (set by the GRADLE_HOME env var), and always downloads a Gradle version mandated by the Android Build tools.
Also make sure, that the Android SDK root environment variable (ANDROID_HOME or ANDROID_SDK_ROOT) is pointing to the SDK's root directory (e.g. $ export ANDROID_HOME="/opt/android-sdk/")[1].
Restart Bamboo after applying the environment variable changes.
In Bamboo, in the build tasks lists, add a new Script task. The interpreter should be '/bin/sh or cmd.exe', the script location should be 'inline', and the script body should contain the call for the parametrized Gradle wrapper, e.g.
gradlew clean build
Point the working subdirectory to the Gradle wrapper's relative location (to the repo root), if necessary.
[Sample Bamboo Android Gradle build script]
After these steps, Bamboo should execute the Gradle wrapper, which in fact should perform the actual build steps.

"Could not initialize class" error running lint target from gradle

I'm working on an Android project with two projects inside it. When trying to run a build with gradlew (./gradlew build), I see the following error:
Execution failed for task ':example:lint'.
Could not initialize class
com.android.build.gradle.tasks.Lint$LintGradleIssueRegistry
With stacktrace enabled, this is listed as a java.lang.NoClassDefFoundError.
Oddly, the first time I ran this (which downloaded dependencies), the build failed with a different error:
Execution failed for task ':example:lint'.
lombok/ast/Node
The gradle wrapper that Android SDK created for the project is using Gradle 2.8.
Could this be a configuration issue with the project or my dev machine? I'm trying to avoid using the Android SDK lint tool as this complains about the projects using Gradle (and I hear it may miss some parts of these projects).
Turned out this was a configuration issue in our build.gradle. The following line had been added for testing and never removed:
configurations.classpath.exclude group: 'com.android.tools.external.lombok'
As such, the classes needed for linting were missing.
The following discussion pointed us in the right direction, in case it's useful to anyone else:
https://github.com/evant/gradle-retrolambda/issues/96

Android Studio how to run gradle sync manually?

I'm debugging Gradle issues in Android Studio and see references to "Run gradle sync", but I'm not sure how to run this command.
How do I run "Gradle sync" from Android studio or Mac terminal?
Android studio should have this button in the toolbar marked "Sync project with Gradle Files"
EDIT: I don't know when it was changed but it now looks like this:
EDIT: This is what it looks like on 3.3.1
OR by going to File -> Sync Project with Gradle Files from the menubar.
WARNING: --recompile-scripts command has been deprecated since gradle's version 5.0.
To check your gradle version, run gradle -v.
./gradlew --recompile-scripts
it will do a sync without building anything.
Alternatively, with command line in your root project
./gradlew build
It will sync and build your app, and take longer than just a Gradle sync
To see all available gradle task, use ./gradlew tasks
In Android Studio 3.3 it is here:
According to the answer https://stackoverflow.com/a/49576954/2914140 in Android Studio 3.1 it is here:
This command is moved to File > Sync Project with Gradle Files.
Keyboard shortcut lovers can add a shortcut for running gradle sync manually by going to File -> Settings -> Keymap -> Plugins -> Android Support -> Sync Project with gradle files (Right click on it to add keyboard shortcut) -> Apply -> OK and you are done. Choose any convenient key as your gradle sync shortcut which doesnot conflict with any other shortcut key, (I have choosen Shift + 5 as my gradle sync key), so next when you want to run gradle sync manually just press this keyboard shortcut key.
I presume it is referring to Tools > Android > "Sync Project with Gradle Files" from the Android Studio main menu.
gradle --recompile-scripts
seems to do a sync without building anything.
you can enable automatic building by
gradle --recompile-scripts --continuous
Please refer the docs for more info:
https://docs.gradle.org/current/userguide/gradle_command_line.html
Shortcut (Ubuntu, Windows):
Ctrl + F5
Will sync the project with Gradle files.
I think ./gradlew tasks is same with Android studio sync. Why? I will explain it.
I meet a problem when I test jacoco coverage report. When I run ./gradlew clean :Test:testDebugUnitTest in command line directly , error appear.
Error opening zip file or JAR manifest missing : build/tmp/expandedArchives/org.jacoco.agent-0.8.2.jar_5bdiis3s7lm1rcnv0gawjjfxc/jacocoagent.jar
However, if I click android studio sync firstly , it runs OK. Because the build/../jacocoagent.jar appear naturally.
I dont know why, maybe there is bug in jacoco plugin. Unit I find running .gradlew tasks makes the jar appear as well. So I can get the same result in gralde script.
Besides, gradle --recompile-scripts does not work for the problem.
I have a trouble may proof gradlew clean is not equal to ADT build clean. And Now I am struggling to get it fixed.
Here is what I got:
I set a configProductID=11111 from my gradle.properties, from my build.gradle, I add
resValue "string", "ProductID", configProductID
If I do a build clean from ADT, the resource R.string.ProductID can be generated. Then I can do bellow command successfully.
gradlew assembleDebug
But, as I am trying to setup build server, I don't want help from ADT IDE, so I need to avoid using ADT build clean. Here comes my problem.
Now I change my resource name from "ProductID" to "myProductID", I do:
gradlew clean
I get error
PS D:\work\wctposdemo> .\gradlew.bat clean
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\work\wctposdemo\app\build.gradle'
* What went wrong:
Could not compile build file 'D:\work\wctposdemo\app\build.gradle'.
> startup failed:
General error during semantic analysis: Unsupported class file major version 57
If I try with:
.\gradlew.bat --recompile-scripts
I just get error of
Unknown command-line option '--recompile-scripts'.
Anyone wants to use command line to sync projects with gradle files, please note:
Since Gradle 5.0,
The --recompile-scripts command-line option has been removed.
https://docs.gradle.org/5.0/userguide/upgrading_version_4.html#potential_breaking_changes
https://docs.gradle.org/current/userguide/command_line_interface.html
https://github.com/gradle/gradle/issues/1425
From terminal:
gradle prepareKotlinBuildScriptModel
NOTE: you can see what android studio is doing by inspecting the "Build" tab. There will be difference windows inside there. One should be "Sync"

How do you use the gradle javafx android builder?

For the gradle javafx builder I've used the tutorial at: https://bitbucket.org/javafxports/android/wiki/Building%20and%20deploying%20JavaFX%20Applications
I downloaded the runtime from here: https://bitbucket.org/javafxports/android/downloads
I'm using javafx in eclipse. I have tried to build the project with theses parameters:
gradle -PDEBUG -PDIR=C:/Users/spencer/Desktop -PNAME=HelloAndroidWorld -PPACKAGE=com.helloworld -PJFX_SDK=C:/Users/spencer/Downloads/dalvik-sdk-latest/dalvik-sdk/android-tools -PJFX_APP=C:/Users/spencer/Documents/Eclipse/Work" "Space/Interactive" "JavaFX/src -PJFX_MAIN=application.Main.java
Here is the message I got afterwards:
C:\Users\spencer>gradle -PDEBUG -PDIR=C:/Users/spencer/Desktop -PNAME=HelloAndro
idWorld -PPACKAGE=com.helloworld -PJFX_SDK=C:/Users/spencer/Downloads/dalvik-sdk
-latest/dalvik-sdk/android-tools -PJFX_APP=C:/Users/spencer/Documents/Eclipse/Wo
rk" "Space/Interactive" "JavaFX/src -PJFX_MAIN=application.Main.java
:help
Welcome to Gradle 1.12.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
BUILD SUCCESSFUL
Total time: 9.871 secs
I cannot find the file on my desktop! When i try adding "createProject" to the end i give me errors.
How do i build a android project?
I am not sure what id did wrong this is my first time trying this please help. All the help so far has been great!
Thanks
you have to give task to a gradle for creating a project give createProject task at the end of all parameters but before that you have to run gradle from your dalvik sdk into the android-tools folder
because it contain the build.gradle file in which createProject task is defined for example
into the command line:
c:\User\dalvik\dalvik-sdk\android-tools> gradle -PDEBUG -PDIR=C:/Users/spencer/Desktop -PNAME=HelloAndroidWorld -PPACKAGE=com.helloworld -PJFX_SDK=C:/Users/spencer/Downloads/dalvik-sdk-latest/dalvik-sdk/android-tools -PJFX_APP=C:/Users/spencer/Documents/Eclipse/Work" "Space/Interactive" "JavaFX/src -PJFX_MAIN=application.Main.java createProject
You haven't run any task. Run gradle tasks to see the list of available tasks. Then pick up a task from the list and run the command once again with task specified. There's also a detailed info:
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help

What commands does Android Studio's `gradle-aware make` perform

Im playing with Android Studio & Gradle and am interesting in what gradle-aware make actually does. The reason for my interest is I was originally under the impression that the default run config for a new AS projects default gradle-aware make runs the gradle assembledebug command (looking at the status at the bottom of AS during build shows the app:assembleDebug task running) and then some install and run commands.
However in testing on a machine that has 1.9 as the installed system gradle version and a wrapper on the project set to 1.10 I get the following
gradle assembleDebug -> Fail : Could not create plugin of type 'AppPlugin'.
./gradlew assembleDebug -> Success
AS Run -> Success
In my mind the above AS Run should fail if gradle-aware make was using gradle assembledebug
Looking at the src I can see the MakeBeforeRunTaskProvider.java class and the relevant commits but I cant see the relevant info
(have answered my own question as in writing it I sort of found the answer - but I assume if this confused me it will someone else so am posting the simple answer anyhow)
Turns out I shouldve looked in settings as you can set the gradle version that should be used - and it defaults to the "default wrapper".
Now when you create a new project in AS you have a default wrapper set up. You can if you want add a custom wrapper section to your root build.gradle of the form
task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}
and then run the task with gradle wrapper to update the projects gradle wrapper (in ./gradle/). This allows the wrapper version to easily be updated.
Im assuming the "Use cusomtizable gradle wrapper" option just runs this wrapper task before any other gradle tasks (which could have a custom url for gradle zip download), whereas "use default..." will just used the last generated wrapper. This will be grayed out if the project has no generated wrapper. Please correct me if you think this is wrong.
This is using AS 0.4.6. Annoyingly there is a bug where syncing gradle files will change the project settings here - seems like to what the previous setting was as Im seeing on one project if going to "default..." and the other to "local". Time to upgrade AS!
Also AS's gradle console window shows the exact commands and output

Categories

Resources