I have a multi module project with Android Studio and I want to get it work with Sonarqube 5.1.
When I run:
gradlew sonarqube
I'm getting "class not found" errors, related to dependency jars. For example:
....
12:56:50.308 ERROR - Class not found: com.google.protobuf.ProtocolMessageEnum
12:56:50.309 ERROR - Class not found: com.google.protobuf.Internal
....
How can I add gradle dependencies without adding the absolute path for each dependency? Isn't it automatic?
This is my configuration
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.0'
}
sonarqube {
properties {
property 'sonar.projectName', 'myApp'
property 'sonar.java.binaries', file('build/intermediates/classes/debug')
property 'sonar.java.libraries','C:/Programs/Android/sdk/platforms/android-22/android.jar'
}
}
And this works:
property 'sonar.java.libraries','C:/Programs/Android/sdk/platforms/android-22/android.jar, PATH/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protobuf-java/2.5.0/a10732c76bfacdbd633a7eb0f7968b1059a65dfa/*.jar
If absolute paths are working for you may try to build the string like this:
def sonarLibraries = buildscript.configurations.classpath.join(",")
property 'sonar.libraries', sonarLibraries
Related
I'm trying to "make project" with Android Studio, and I'm getting this error:
Execution failed for task ':myApp:processGoogleDebugManifest'.
Could not get unknown property 'manifestOutputDirectory' for task ':myApp:processGoogleDebugManifest' of type com.android.build.gradle.tasks.ProcessMultiApkApplicationManifest.
Any help please?
EDIT: This error occurred after I updated to gradle v6.5 and plugin v4.1.0. If I revert to gradle v6.1.1 and plugin v4.0.0 the error disappears.
I encountered this same issue today, in my case it was caused by an outdated version of Huawei's AG Connect plugin. I was using com.huawei.agconnect:agcp:1.2.1.301, but when I updated it to com.huawei.agconnect:agcp:1.4.1.300 the issue was fixed.
See Latest Huawei's AG Connect plugin here: https://developer.huawei.com/latest/plugin/agconnect ...Just scroll, you'll find it there haha!
But if Huawei's plugin is not the problem you are having, you can debug the issue by running gradle with --stacktrace option to see where the issue originates from. In Android Studio you can add command line options for gradle in Settings/Build, Execution, Deployment/Compiler/Command-line options.
This solved my same problem:
In the project level build.gradle, replace this:
classpath 'com.huawei.agconnect:agcp:1.3.1.300'
with this:
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Reference: https://github.com/Tencent/tinker/issues/1471#issuecomment-710777366
If you're using bugsnag, replace the following line
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:4.+'
with:
classpath 'com.bugsnag:bugsnag-android-gradle-plugin:5.+'
For further detail, see this issue: Fails with AGP 4.1.0-alpha04 and this comment.
I write it here because this solution saved my day :
We can fix this by simply replacing references to
manifestOutputDirectory
by
multiApkManifestOutputDirectory
enter code here
in your gradle tasks
For example :
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
output.processManifest.doLast { task ->
def outputDir = multiApkManifestOutputDirectory.asFile.get()
String manifestMergerpath = "$outputDir/AndroidManifest.xml"
writeManifest(manifestMergerpath, placeholders)
}
}
}
android.applicationVariants.all {
outputs.all {
processManifestProvider.configure {
val multiApkManifestOutputDirectory = (this as ProcessMultiApkApplicationManifest)
.multiApkManifestOutputDirectory // 👈
doLast {
multiApkManifestOutputDirectory.get()
.asFile
.walkTopDown()
.forEach {
}
}
}
}
}
I am trying to integrate code coverage in gradle Kotlin as suggested in https://techblog.tbauctions.com/kotlin-azure-and-code-coverage/ but it's not working, below are the project files.
build.gradle.kts
plugins {
jacoco
}
val test by tasks.getting(Test::class) {
useJUnitPlatform { }
}
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")
}
Error - Task with name 'test' not found in project ':app'
Also tried https://docs.gradle.org/current/userguide/jacoco_plugin.html
How to generate and publish Code Coverage in gradle kotlin using Azure DevOps?
According to the error message:
Error - Task with name 'test' not found in project ':app'
It seems the task called test is not provided in the project. When using a JVM language plugin like Java in Gradle, a task called test is automatically provided. This task runs all tests under src/test by default.
The Java plugin adds a number of tasks to your project, including the test task:
The Java Plugin:
So, make sure you have add plugin Java in Gradle.
You could check this document for some more details.
Hope this helps.
I'm trying to use 3 of the dagger2 compiler options in my android project.
but it seems none of them actually work.
I have pasted the code from here to my gradle.properties and even compiler options of AS settings.
the 3 that I'm interested in are:
-Adagger.fastInit=enabled
-Adagger.formatGeneratedSource=disabled
-Adagger.gradle.incremental
the fastinit and codeformatting just don't work (judging by the code that is generated) but the incremental cause a compile error saying:
no compiler option found.
the versions that I'm using are:
dagger : 2.18
gradle : 5.2.1
kotlin : 1.3.21
androidPlugin : 3.3.1
For projects with multiple modules, the top build.gradle can be updated with this
allprojects {
repositories {
...
}
afterEvaluate {
extensions.findByName('kapt')?.arguments {
arg( "dagger.formatGeneratedSource", "disabled" )
}
}
}
Perhaps you should try without "A"
dagger.fastInit=enabled
dagger.formatGeneratedSource=disabled
dagger.gradle.incremental=enabled
Also can try directly in build.gradle, but this should be done for each project.
kapt {
arguments {
arg('dagger.fastInit', 'enabled')
arg('dagger.formatGeneratedSource', 'disabled')
arg('dagger.gradle.incremental', 'enabled')
}
}
I am trying to add NanoHTTPD to my Android project.
As mentioned in README.md, I added
dependencies {
runtime(
[group: 'org.nanohttpd', name: 'nanohttpd', version: '2.3.1'],
)
}
it is giving error:
Could not find method runtime() for arguments [{group=org.nanohttpd, name=nanohttpd, version=2.3.1}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I also tried adding
repositories {
mavenCentral()
}
mentioned elsewhere, but same error.
I tried the usual way:
implementation 'org.nanohttpd.nanohttpd:2.3.1'
it gives error:
Failed to resolve: org.nanohttpd.nanohttpd:2.3.1:
I am using Android Studio 3.2.1
There seem to be so many people happily using it in Android. What am I missing?
In your gradle file, separate group and artifact ids with a : instead of .. That is, replace
implementation 'org.nanohttpd.nanohttpd:2.3.1'
with
implementation 'org.nanohttpd:nanohttpd:2.3.1'
I need to create Jar and copy to lib folder, which is done in following task :
task copyJarToLib(type: Copy, dependsOn: 'createJar') {
from "build/libs/lib1.jar"
from "build/libs/lib2.jar"
into "../App/libs/"
}
I have to execute this after apk generation. So, I am calling following instruction at the end of the module-app build.gradle :
assembleDebug.finalizedBy(copyJarToLib)
Issue is observed after upgrading the gradle plugin to 3.1.0 and gradle to 4.4.
Same implementation is working fine with gradle 2.3.
If you want to execute something at the end of build, you can do it as follows:
gradle.buildFinished {
copy {
from "build/libs/lib1.jar"
from "build/libs/lib2.jar"
into "../App/libs/"
}
}
If you want to execute task before apk is built the you can:
afterEvaluate {
project.tasks.findByName('preDebugBuild').dependsOn(':<module>:copyJarToLib')
}
base on Android Studio 2020.3.1, you can use follow codes
afterEvaluate {
project.tasks.findByName('preDebugBuild').dependsOn(copyJarToLib)
}