I have set up a pipeline that runs my tests in microsoft azure pipelines. On my local machine this works fine and the jetified-libidpmobile-debug.jar file is found in the gradle system directory on my machine:
/Users/jimclermonts/.gradle/caches/transforms-2/files-2.1/efad9765ab457848824459e0c76abddc/jetified-libidpmobile-debug.jar
this is my build.gradle:
debugImplementation files('libs/libidpmobile-debug.jar')
From what I understand, jetified-libidpmobile-debug.jar is automatically created by jetifier from the libidpmobile-debug.jar file.
Output:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptDebugKotlin'.
> Could not resolve all files for configuration ':app:_classStructurekaptDebugKotlin'.
> Failed to transform file 'jetified-libidpmobile-debug.jar' to match attributes {artifactType=class-structure, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
> Execution failed for StructureArtifactTransform: /Users/iosadmin/.gradle/caches/transforms-2/files-2.1/1e14bb7ec832a0c2c967e6c977ddd9b9/jetified-libidpmobile-debug.jar.
> error in opening zip file
Here is the part of my azure-pipelines.yml that assembles the debug and tests the unit tests:
trigger:
- master
pool:
name: Mobile-Pool
steps:
- task: Gradle#2
inputs:
workingDirectory: ''
gradleWrapperFile: 'gradlew'
gradleOptions: '-Xmx4096m'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
tasks: 'assembleDebug testDebugUnitTest'
I tried the solutions in this post, this post and this post with no result.
The jar file is 4mb big and is the only file that is in the code repository instead of some maven repository.
Updated Gradle to the latest:
classpath 'com.android.tools.build:gradle:4.0.0-beta05'
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Tried to edit the androidmanifest like this:
tools:replace="android:appComponentFactory"
android:appComponentFactory="androidx.core.app.CoreComponentFactory">
build.gradle:
kotlinOptions {
jvmTarget = '1.8'
}
compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
I used jetifier-standalone to jetify the files. Added it to gradle.properties:
android.jetifier.blacklist = libidpmobile
and now it works.
It looks like the databinding issue from the error The following options were not recognized by any processor: '[android.databinding.minApi....
You can try adding below line to build.gradle file.
kapt "com.android.databinding:compiler:$gradle_version"
You can check out below similar threads for more information:
Android Databinding build fail after Gradle plugin update with migration to annotationProcessor
Fail make project if android data binding enabled
Hope above helps!
Related
Today I updated gradle and kotlin dependencies in android studio.
The new versions are these:
kotlin_version = "1.5.10"
...
jacoco {
toolVersion = "0.8.6"
}
...
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
The test coverage report task fails with the following error:
2021-05-27T16:57:49.150+0200 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter] Executing actions for task ':consumerkit:testDebugUnitTestCoverage'.
2021-05-27T16:57:49.304+0200 [DEBUG] [org.codehaus.groovy.vmplugin.VMPluginFactory] Trying to create VM plugin `org.codehaus.groovy.vmplugin.v9.Java9` by checking `java.lang.Module`, but failed:
java.lang.ClassNotFoundException: java.lang.Module
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.groovy.vmplugin.VMPluginFactory.lambda$createPlugin$0(VMPluginFactory.java:61)
at java.security.AccessController.doPrivileged(Native Method)
For Kotlin 1.5 you should use JaCoCo 0.8.7 instead of 0.8.6 - see https://github.com/jacoco/jacoco/pull/1164 and the full changelog at https://www.jacoco.org/jacoco/trunk/doc/changes.html
Example snippet:
// build.gradle or build.gradle.kts
jacoco {
toolVersion = "0.8.7"
}
I already had the
jacoco {
toolVersion = "0.8.7"
}
configured but it was not working anyway, what fixed the problem was to follow this comment here
In your module build.gradle switch back to:
android {
//....
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
don't worry, it won't break anything if you were not using Java 11 language features yet, AGP 7 is still compatible with JDK 8 as target.
Then you need to force AGP to use the 0.8.7 version and not the default 0.8.3 one. In your allprojects block in the root build.gradle file, add this:
allprojects {
//... other things
// workaround to fix an auto-import of a lower Jacoco version
resolutionStrategy {
eachDependency { details ->
if ('org.jacoco' == details.requested.group) {
details.useVersion "0.8.7"
}
}
}
}
and now it should work using:
AGP 7.0.X
Kotlin 1.5.X
JDK 11 (embedded with AS)
Simply doing
jacoco {
toolVersion = "0.8.7"
}
was not enough for me. I also had to override the version that Android was using so that the androidJacocoAnt dependency also uses 0.8.7. (./gradlew app:dependencies) Simply add this to your gradle too
android.jacoco.version = "0.8.7"
It's quite old thread, but these solutions did not solve my problems completely in Android project (actually written in Java - not in Kotlin), so I will add my solutions here. Maybe someone will find it helpful.
Except of updating jacoco toolVersion to 0.8.7, I also had to update execution data in my jacoco config as follows:
project.afterEvaluate {
tasks.create(name: "${unitTestTask}Coverage", type: JacocoReport,
dependsOn: [
"$unitTestTask",
":sdk:testDebugUnitTest",
":sdk:connectedCheck"
]) {
/* all jacoco custom configuration goes here... */
executionData(fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec",
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
"outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
]))
}
}
in this configuration I had to add the following line:
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec"
which wasn't there before because file with generated report used by sonar was generated in the new location. Report is generated with gradle task testDebugUnitTestCoverage. After all of that, I'm able to generate test coverage report including connected/instrumentation Android tests and regular unit tests in java via sonar.
I want to build a library with Jetpack Compose and publishing it using jitpack.io.
Im using the canary version of android studio
android studio canary version.
I've build the project, push it to Github, made a release then I've put the link of my repo in jitpack.io to generate the lib dependency link "implementation 'com.github.user:compose-lib:Tag'" but something went wrong and I got this log error from jitpack :
Build starting...
Start: Tue Apr 27 14:25:17 UTC 2021 0c5235afbe25
Git:
0.9.0-0-g13dbaf9
commit 13dbaf941d2c59d8e70ed64b868488abb7f3f2e1
Author: username
Date: Tue Apr 27 14:29:45 2021 +0200
gradle plugin require Java 11 to run
Found Android manifest
Android SDK version: . Build tools: 30.0.3
Installing Build-tools 30.0.3
Found gradle
Gradle build script
Found gradle version: 7.0.
Using gradle wrapper
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Downloading https://services.gradle.org/distributions/gradle-7.0-rc-1-bin.zip
.
Unzipping /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld/gradle-7.0-rc-1-bin.zip to /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld
Set executable permissions for: /home/jitpack/.gradle/wrapper/dists/gradle-7.0-rc-1-bin/14lahl8r8vkgd4j5n81i3rsld/gradle-7.0-rc-1/bin/gradle
Welcome to Gradle 7.0-rc-1!
Here are the highlights of this release:
- File system watching enabled by default
- Support for running with and building Java 16 projects
- Native support for Apple Silicon processors
- Dependency catalog feature preview
For more details see https://docs.gradle.org/7.0-rc-1/release-notes.html
------------------------------------------------------------
Gradle 7.0-rc-1
------------------------------------------------------------
Build time: 2021-03-23 01:02:30 UTC
Revision: f5bf7ade373b74058e49f07749083b4c3075549a
Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 1.8.0_252 (Private Build 25.252-b09)
OS: Linux 4.14.63-xxxx-std-ipv6-64 amd64
0m3.102s
Getting tasks: ./gradlew tasks --all
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jitpack/build/mylib/build.gradle' line: 2
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
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.
* Get more help at https://help.gradle.org
BUILD FAILED in 24s
Tasks:
WARNING:
Gradle 'install' task not found. Please add the 'maven' or 'android-maven' plugin.
See the documentation and examples: https://jitpack.io/docs/
Adding maven plugin
Found android library build file in mylib
Running: ./gradlew clean -Pgroup=com.github.user -Pversion=0.9.0 install
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
> Configure project :
Gradle version Gradle 7.0-rc-1
FAILURE: Build failed with an exception.
* Where:
Build file '/home/jitpack/build/mylib/build.gradle' line: 2
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.library']
> Failed to apply plugin 'com.android.internal.library'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
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.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/7.0-rc-1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
Build tool exit code: 0
Looking for artifacts...
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
Looking for pom.xml in build directory and ~/.m2
2021-04-27T14:25:58.25891409Z
Exit code: 0
ERROR: No build artifacts found
And here my build.gradle file of my library:
plugins {
id 'com.android.library'
id 'kotlin-android'
}
android {
compileSdk 30
buildToolsVersion "30.0.3"
defaultConfig {
minSdk 21
targetSdk 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = '11'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerVersion "1.4.32"
kotlinCompilerExtensionVersion "1.0.0-beta05"
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = "11"
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.0-alpha07'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
}
I changed the java version from 1.8 to 11 but still doesn't work.
here my android studio config: Gradle JDK
File > project structure > SDK Location: SDK Location
Any help would be appreciated!
[EDIT] Problem Solved by configuring Jitpack to run on Java 11. I added jitpack.yml file which contains
jdk:
- openjdk11
You can refer to this article for more details.
Is the path to JDK correct? You could check inside File > project structure > sdk location.
please verify if this location is based on jdk 11.
When enabling jacoco with gradle kotlin dsl it fails because it looks at build.gradle file instead of build.gradle.kts file.
Here is the error :
##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
app/build.gradle.kts
plugins {
jacoco
}
tasks.withType(JacocoReport::class.java).all {
reports {
xml.isEnabled = true
xml.destination = File("$buildDir/reports/jacoco/report.xml")
}
}
tasks.withType<Test> {
jacoco {
toolVersion = "0.8.3"
reportsDir = file("$buildDir/reports/jacoco")
}
finalizedBy("jacocoTestReport")
}
Azure DevOps task
- task: Gradle#2
displayName: Gradle Build
inputs:
gradleWrapperFile: 'gradlew'
tasks: ':app:assembleDevDebug :networking:lintDebug :app:lintDevDebug --warning-mode all'
publishJUnitResults: false
testResultsFiles: '**/TEST-*.xml'
javaHomeOption: 'JDKVersion'
sonarQubeRunAnalysis: false
codeCoverageToolOption: 'jaCoCo'
Messages
##[warning]Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
##[warning]Failed to enable code coverage: Unable to append code coverage data: Error: File or folder doesn't exist: /home/vsts/work/1/s/build.gradle
are produced by AzureDevOps Gradle Task due to usage of option
codeCoverageToolOption: 'jaCoCo'
in your configuration of this task, because implementation of AzureDevOps Gradle Task contains hardcoded value build.gradle:
https://github.com/Microsoft/azure-pipelines-tasks/blob/9818b165441796437ca881c3f01bd7d90ee6856e/Tasks/GradleV2/gradletask.ts#L66
https://github.com/microsoft/azure-pipelines-tasks/issues/9340
quoting comment from the above bug ticket
The way for you to use code coverage would be to enable it in your build config files and publish them using another task - PublishCodeCoverageResults
I am getting the following error when running espresso test ./gradlew connectedAndroidTest
> Task :app:fixStackFramesLiveDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:fixStackFramesLiveDebugAndroidTest'.
> Cannot convert the provided notation to a File or URI: classes.jar (androidx.databinding:databinding-adapters:3.4.1).
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
app/build.gradle contains the following
...
android {
.....
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...
}
dataBinding {
enabled = true
}
}
...
Irrespective of espresso dependencies, I am getting the above error. Can someone please help to resolve this issue. I am new to android and espresso.
I am not sure if I had missed out information. Please let know if needed.
On Android Studio 4.0 canary 4 with Gradle Kotlin DSL enabled, I got the kinda same error:
Unable to resolve dependency for ':app#debug/compileClasspath': Cannot convert the provided notation to a File or URI: {dir=libs, include=[*.jar]}.
After I changed my build script from
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}
to
dependencies {
implementation(fileTree(Pair("dir", "libs"), Pair("include", listOf("*.jar"))))
}
everything works well. WTF.
I ran into this error after updating gradle to 3.4.+ After I downgraded to 3.3.2 I was able to build without any issues.
I am trying to build and imported Android project in Android Studio/Eclipse.
My goal is to write automated test to the current project. First, I am trying to build the project and then to make an apk file of it so I will be able to execute real device/emulator tests on it.
Here are my available Gradle tasks
There is no build or test or assemble and etc. tasks which are I am looking to use so I will reach my goal.
Here is my project tree and both build.gradle files
`
apply plugin: "java"
repositories {
jcenter()
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.13
testCompile 'junit:junit:4.12'
}
and
apply plugin: 'com.android.application'
version = "1.2"
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "sdk.mobfox.com.appcore"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
archivesBaseName = "MobFox-Android-SDK-Client-" + version + ".apk"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize = "4g"
}
lintOptions {
abortOnError false
}
}
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.google.android.gms:play-services-ads:11.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.danikula:videocache:2.7.0'
testCompile 'junit:junit:4.12'}
I tried to open the project in Android Studio but got the same state.
I opened a new Gradle project in Eclipse and saw that the tasks I am looking for are available there - I believe because of the 'java-library' plugin which added to the build.gradle root file but I use the same plugin in my root build file and did not receive what I expected.
I was succeeded to execute the Gradle "tasks" which gave me the next response in console :
Working Directory: C:\Users\orit\Desktop\mobFox\MobFox-Android-SDK-master\MobFox-Android-SDK-master
Gradle User Home: C:\Users\orit.gradle
Gradle Distribution: Specific Gradle version 4.1
Gradle Version: 4.1
Java Home: C:\Program Files\Java\jdk1.8.0_91
JVM Arguments: None
Program Arguments: None
Gradle Tasks: tasks
:tasks
All tasks runnable from root project
Build tasks
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.
Build Setup tasks
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.
Documentation tasks
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
buildEnvironment - Displays all buildscript dependencies declared in root project 'MobFox-Android-SDK-master'.
components - Displays the components produced by root project 'MobFox-Android-SDK-master'. [incubating]
dependencies - Displays all dependencies declared in root project 'MobFox-Android-SDK-master'.
dependencyInsight - Displays the insight into a specific dependency in root project 'MobFox-Android-SDK-master'.
dependentComponents - Displays the dependent components of components in root project 'MobFox-Android-SDK-master'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'MobFox-Android-SDK-master'. [incubating]
projects - Displays the sub-projects of root project 'MobFox-Android-SDK-master'.
properties - Displays the properties of root project 'MobFox-Android-SDK-master'.
tasks - Displays the tasks runnable from root project 'MobFox-Android-SDK-master'.
Verification tasks
check - Runs all checks.
test - Runs the unit tests.
Rules
Pattern: clean: Cleans the output files of a task.
Pattern: build: Assembles the artifacts of a configuration.
Pattern: upload: Assembles and uploads the artifacts belonging to a configuration.
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
**1. What is the reason I cannot get all the task I got when I open a new project?
How can I add these tasks so I will be able to create apk file, build and execute integration tests?**
task, you write in project level build.gradle file. See below pic for the reference.
You are posting module level build.grale file.
Applying com.android.application should be enough, you should not apply java plugin on the root either and add dependencies there.
Operate on your app project, with Java specific stuff.
For more reference how to structure your project.
https://developer.android.com/studio/build/index.html