I am new in Android studio & Gradle.
My project structure is like this:
MyProject
-LibModuleOne
-...
-build.gradle
-LibModuleTwo
- ...
-buld.gradle
-AppModule
-...
-build.gradle
buld.gradle
On command line, under MyProject/ , ./gradlew --version shows me that I am using gradle 2.1:
./gradlew --version
------------------------------------------------------------
Gradle 2.1
------------------------------------------------------------
Build time: 2014-09-08 10:40:39 UTC
Build number: none
Revision: e6cf70745ac11fa943e19294d19a2c527a669a53
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_25 (Oracle Corporation 25.25-b02)
OS: Mac OS X 10.8.5 x86_64
But, if I check the version under MyProject/LibModuleOne/ or MyProject/LibModuleTwo/ or MyProject/AppModule/ they all show me that I am using gradle 1.12:
./gradlew --version
------------------------------------------------------------
Gradle 1.12
------------------------------------------------------------
Build time: 2014-04-29 09:24:31 UTC
Build number: none
Revision: a831fa866d46cbee94e61a09af15f9dd95987421
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
Ivy: 2.2.0
JVM: 1.8.0_25 (Oracle Corporation 25.25-b02)
OS: Mac OS X 10.8.5 x86_64
The build.gradle of project root declares using Android plugin version0.13.3 :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
}
}
In Android studio, File-->Project structure --> shows Gradle 2.1
Why gradle wrapper shows different version in sub-modules than project root ? How to make all my sub-modules use Gradle 2.1 ?
You appear to have multiple wrappers installed (otherwise ./gradlew wouldn't work from subdirectories). You need to remove all gradlew scripts and gradle/wrapper directories except for the ones in the root project's directory.
Related
I have a project that compiles fine when I run ANDROID_HOME=/.../Library/Android/sdk gradle clean assembleDebug. But when I try to run the same on a github action like this...
on:
push:
branches:
- '**'
jobs:
test:
name: Analyze Android
runs-on: ubuntu-latest
steps:
- name: Checkout App
uses: actions/checkout#v2
- uses: actions/setup-java#v3
with:
distribution: temurin
java-version: 11
- name: Setup Gradle
uses: gradle/gradle-build-action#v2
- name: Setup Android SDK
uses: android-actions/setup-android#v2
- name: Assemble
run: |
./gradlew clean assembleDebug
I get
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:mergeDebugAssets'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not resolve project :DTO.
Required by:
project :app
project :app > project :UI
project :app > project :Data
project :app > project :Domain
> No matching configuration of project :DTO was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '7.2.1', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- None of the consumable configurations have attributes.
But the DTO project does exist and as I said works locally. I checked the versions and they look to be the same...
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 15.0.2 (Oracle Corporation 15.0.2+7-27)
OS: Mac OS X 10.16 x86_64
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.16 (Eclipse Adoptium 11.0.16+8)
OS: Linux 5.15.0-1014-azure amd64
Why does it work locally but not via Github Actions?
Updates
It looks like it is because the library is setup like this...
plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
}
instead of like the rest...
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
So it finds the others but not this one. But I tried converting to an android app and I get the same issue.
In my case it was because my local box was OSX (not case sensitive) and the build box was Ubuntu (case sensitive). Once the name was lowercased it worked.
I think your computer doesn't have enough space(RAM) for Build. I also faced the similar issue but it got resolved when I Increased my internal ram.
My task is defined inside app/build.gradle
rootProject.configurations has no configuration while configurations has everything e.g. "implementation", "testImplementation" etc.
Why?
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_191 (Oracle Corporation 25.191-b12)
OS: Mac OS X 10.14.6 x86_64
The build.gradle file in the app folder defines a sub module (or sub project). The build.gradle file in the root folder defines the root project.
The configurations are added by plugins and in most use cases there is no need to apply a plugin in the root project.
Error:Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
Tried everything, Android Studio still does not works. Re-installed 10 times, cleaned all .gradle .android folder. Created example project from scratch. Tried changing the gradle version. Nothing almost nothing works.
There is no system gradle, my Java version is javac 1.8.0_40
Contents of gradle config
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here are the contents of idea.log
2015-11-08 22:40:39,654 [ 471024] WARN - nal.AbstractExternalSystemTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
at org.jetbrains.plugins.gradle.service.project.BaseProjectImportErrorHandler.getUserFriendlyError(BaseProjectImportErrorHandler.java:158)
at org.jetbrains.plugins.gradle.service.project.BaseGradleProjectResolverExtension.getUserFriendlyError(BaseGradleProjectResolverExtension.java:438)
at com.android.tools.idea.gradle.project.AndroidGradleProjectResolver.getUserFriendlyError(AndroidGradleProjectResolver.java:348)
at org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension.getUserFriendlyError(AbstractProjectResolverExtension.java:164)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:366)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:332)
at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:225)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:97)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:65)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4.execute(ExternalSystemUtil.java:540)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5$2.run(ExternalSystemUtil.java:621)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:695)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
2015-11-08 22:40:39,655 [ 471025] WARN - radle.project.ProjectSetUpTask -
2015-11-08 22:40:39,655 [ 471025] INFO - radle.project.ProjectSetUpTask - Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
Consult IDE log for more details (Help | Show Log)
2015-11-08 22:40:39,655 [ 471025] INFO - ls.idea.gradle.GradleSyncState - Sync with Gradle for project 'My Application' failed: Could not create an instance of Tooling API implementation using the specified Gradle distribution 'https://services.gradle.org/distributions/gradle-2.4-all.zip'.
Based on suggestions I installed gradle seperately, I had to fix this error https://issues.gradle.org/browse/GRADLE-1451 but I now have ANDROID_HOME, gradle defined and gradle --version works.
------------------------------------------------------------
Gradle 2.7
------------------------------------------------------------
Build time: 2015-09-14 07:26:16 UTC
Build number: none
Revision: c41505168da69fb0650f4e31c9e01b50ffc97893
Groovy: 2.3.10
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS: Mac OS X 10.9.5 x86_64
**Yet I am still getting the same error from Android Studio. Also in a bizarre manner it simply refuses to accept the gradle home folder, always showing error that Gradle home folder is incorrect, even when I used lib or bin sub directory the error still remains. And it automatically switches back to the wrapper. **
Error:Could not create an instance of Tooling API implementation using the specified Gradle installation '/Users/aub3/gradle'.
When built from command like using 'gradle build' I get following error
:app:compileReleaseSources
:app:preDexRelease
:app:dexRelease
:app:packageRelease
:app:assembleRelease
:app:assemble
:app:compileLint
:app:lint
Ran lint on variant debug: 4 issues found
Ran lint on variant release: 4 issues found
Wrote HTML report to file:/Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.html
Wrote XML report to /Users/aub3/IdeaProjects/Dsdsadasd/app/build/outputs/lint-results.xml
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:processDebugUnitTestJavaRes UP-TO-DATE
:app:compileDebugUnitTestJavaWithJavac
:app:compileDebugUnitTestSources
:app:mockableAndroidJar
:app:assembleDebugUnitTest
:app:testDebugUnitTest
java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to org.gradle.logging.internal.slf4j.OutputEventListenerBackedLoggerContext
at org.gradle.logging.internal.slf4j.Slf4jLoggingConfigurer.configure(Slf4jLoggingConfigurer.java:42)
at org.gradle.logging.internal.DefaultLoggingConfigurer.configure(DefaultLoggingConfigurer.java:34)
at org.gradle.logging.internal.LoggingSystemAdapter.setLevel(LoggingSystemAdapter.java:55)
at org.gradle.logging.internal.LoggingSystemAdapter.on(LoggingSystemAdapter.java:42)
at org.gradle.logging.internal.DefaultLoggingManager$StartableLoggingSystem.start(DefaultLoggingManager.java:191)
at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:60)
at org.gradle.logging.internal.DefaultLoggingManager.start(DefaultLoggingManager.java:31)
at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:58)
at org.gradle.process.internal.child.ImplementationClassLoaderWorker.execute(ImplementationClassLoaderWorker.java:41)
at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:49)
at org.gradle.process.internal.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:33)
at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.run(GradleWorkerMain.java:69)
at jarjar.org.gradle.process.internal.launcher.GradleWorkerMain.main(GradleWorkerMain.java:74)
:app:testDebugUnitTest FAILED
FAILURE: Build failed with an exception.
I finally got gradle to assemble android project and install on a devide via gradle installDebug task using command line. Android Studio however still does NOT works.
Error:Could not create an instance of Tooling API implementation using the specified Gradle installation '/Users/aub3/gradle'.
Solved
I could get gradle wrapper to work with following
DEFAULT_JVM_OPTS="-Djava.ext.dirs="
However there is no way to use this setting with Android Studio.
Also unlike what I read online , there are multiple directories
[java.ext.dirs] = /Users/aub3/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java.
I went to each directory and removed Jar files for Loggers, sl4j and others. With this I was able to get Android Studio to work.
Check for conflicts in /Library/Java/Extensions.
In my case, I had logback-classic.jar, logback-core.jar, slf4j-api.jar and xuggle-xuggler.jar all soft-linked from some directory /usr/local/xuggler/share/java/jars/ (which I don't recall what may have installed it).
I just put these files (or links) away and now I'm able to use Gradle both from the command line and from within Android Studio. (I created a script to restore the soft-links in case my setup is broken somewhere else, but so far, I haven't run into any problems).
You can Download GRADLE on website. Gradle Download.
Save on any directory (example: /Users/ihojose/Documents/gradle).
Open Console and add system variable.
vi ~/.profile
Copy and paste the following text into the .profile file:
GRADLE_HOME=/Users/ihojose/Documents/gradle;
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin
Test gradle in console
gradle -version
If result if similar to this:
------------------------------------------------------------
Gradle 1.0-rc-3
------------------------------------------------------------
Gradle build time: Monday, Novenber 9, 2015 16:10:52 PM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 2.6.0 compiled on October 21 2015
Ivy: 2.2.0
JVM: 1.8.0_68 (Apple Inc. 20.6-b01-415)
OS: Mac OS X 11.0.1 x64
Define ANDROID_HOME
Click here for How to define ANDROID_HOME
Now you can use Android Studio.
I'm trying to build Android projects on the OSX (Mavericks 10.9.5) command line using this how-to: http://developer.android.com/tools/building/building-cmdline.html.
This How-To explains the use of assembleDebug/assembleRelease to build an Android project.
Unfortunately gradle doesn't create the assembleDebug or assembleRelease targets.
Executing ./gradlew assembleDebug returns this:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'assembleDebug' not found in root project 'test'.
* Try:
Run gradlew tasks to get a list of available tasks. Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.826 secs
Steps:
android create project
The test project has been created with android create project --path . --name "DummyAPK" --target android-21 --package com.dummyapk.dummyapk --activity DummyActivity
which returned
Created directory /Users/user/Documents/test/src/com/dummyapk/dummyapk
Added file ./src/com/dummyapk/dummyapk/DummyActivity.java
Created directory /Users/user/Documents/test/res
Created directory /Users/user/Documents/test/bin
Created directory /Users/user/Documents/test/libs
Created directory /Users/user/Documents/test/res/values
Added file ./res/values/strings.xml
Created directory /Users/user/Documents/test/res/layout
Added file ./res/layout/main.xml
Created directory /Users/user/Documents/test/res/drawable-xhdpi
Created directory /Users/user/Documents/test/res/drawable-hdpi
Created directory /Users/user/Documents/test/res/drawable-mdpi
Created directory /Users/user/Documents/test/res/drawable-ldpi
Added file ./AndroidManifest.xml
Added file ./build.xml
Added file ./proguard-project.txt
gradle init
After that I executed gradle init, which returned
:wrapper
:init
BUILD SUCCESSFUL
gradlew tasks
Querying the available tasks with gradlew tasks returns (isn't there missing something?)
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'test'. [incubating]
dependencies - Displays all dependencies declared in root project 'test'.
dependencyInsight - Displays the insight into a specific dependency in root project 'test'.
help - Displays a help message.
projects - Displays the sub-projects of root project 'test'.
properties - Displays the properties of root project 'test'.
tasks - Displays the tasks runnable from root project 'test'.
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 3.474 secs
My Java version is
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
..and Gradle version (installed via brew) is
------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------
Build time: 2014-11-24 09:45:35 UTC
Build number: none
Revision: 6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.7.0_60 (Oracle Corporation 24.60-b09)
OS: Mac OS X 10.9.5 x86_64
What am I missing to be able to build an Android project on the command line?
android create project does not create a gradle friendly structure. It creates an ant friendly structure. You have two options depending on your intentions.
use ant to build your project ( not currently supported by Android team )
use Android Studio to generate a gradle friendly project structure.
num 2 is the recommended approach by the Android team. It's as simple as dl'ing Android Studio and creating a new project. From there you should be able to create a new project that can be built with ./gradlew build
try This:
./android create project -p AppPAKTGV -a Main -k com.example.apppaktgv -t android-23 -g -v 0.11.+
it's works but when i try target 24 or 25 not work i don't now
Try to do this and note
a) you need to type tools/android under Step 3 (like step 2: Execute)
-- but as said the ant structure is not helpful
-- not sure I can go from there
b) I follow the advice and also ensure get the platform-tools
-- I can build
-- I can get that .apk
-- I can adb install (I rename any existing .apk)
Seems working!
i m try to build ndk project in android studio but it will give me error like libopencv.so file not found.
yes I have included all the .so files Under jniLibs as instructed
and I am using the
Gradle 1.10
————————————————————
Build time: 2013-12-17 09:28:15 UTC
Build number: none
Revision: 36ced393628875ff15575fa03d16c1349ffe8bb6
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.9.2 compiled on July 8 2013
Android studio 0.5.3.
please let me know how can I resolve this.
In Android.mk, add
LOCAL_LDLIBS := $(LOCAL_PATH)/jniLibs/libopencv.so