I try to use last SonarQube plugin for Gradle on an Android project.
I follow this:
http://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Gradle
My root.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
plugins {
id "org.sonarqube" version "2.0.1"
}
allprojects {
repositories {
jcenter()
}
}
My app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxxxxx.xxxxxx"
minSdkVersion 15
targetSdkVersion 17
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 232
versionName "2.3.2"
}
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
testOptions {
unitTests.returnDefaultValues = true
}
}
sonarqube {
properties {
property "sonar.projectName", "xxxxx"
property "sonar.projectKey", "org.sonarqube:com.xxxxxxx.xxxxxxxx"
property "sonar.sources", "src/main/java"
property "sonar.java.binaries","build/intermediates/classes"
property "sonar.tests", "src/test/java"
property "sonar.android.lint.report", "build/lint-results.xml"
property "sonar.junit.reportsPath", "build/test-results/debug/"
}
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'
}
I run
./gradlew sonarqube -Dsonar.verbose=true
Logs:
Incremental java compilation is an incubating feature.
:sonarqube
Bytecode of dependencies was not provided for analysis of source files, you might end up with less precise results. Bytecode can be provided using sonar.java.libraries property
sonar.binaries and sonar.libraries are deprecated since version 2.5 of sonar-java-plugin, please use sonar.java.binaries and sonar.java.libraries instead
Bytecode of dependencies was not provided for analysis of test files, you might end up with less precise results. Bytecode can be provided using sonar.java.test.libraries property
Class 'com/xxxxxx/xxxxxxx/ChangelogActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ChangelogActivity$1' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity' is not accessible through the ClassLoader.
Class 'com/xxxxxx/xxxxxxx/ConfigActivity$1' is not accessible through the ClassLoader.
I obtain this error msg on all my classes.
Unfortunately due to complexity of Android Gradle projects (ability to have several flavors in a single project for example) we are not able to automatically collect all information we need to run a SonarQube analysis without any extra config.
Please follow: https://jira.sonarsource.com/browse/SONARGRADL-6
Related
I am trying to debug native (C/C++) code inside my Android project but the breakpoints are not hitting. Tried many proposed solutions like here, here, here, here and a few others I saw but no success.
Debugging normal Java code works fine, stops on set breakpoints as expected. However when setting breakpoints on the C/C++ code, it says after launching, that it didn't find any line of code respective to that breakpoint so it won't be hit.
What I found mostly funny is, if I hit a breakpoint right after going into the native code, and then stepping in, it not only goes in, but also allows me at that point to then set breakpoints on the native code. So it seems it is not loading the native libs during debugging somehow I guess... and after I force to step in from the Java into native, he then enables something and then I am able to set new breakpoints on the native code and they hit as expected. Am I missing any silly configuration?
I am using Android Studio Electric Eel 2022 (up-to-date), NDK and SDK version can be found below.
Here is my build.gradle from project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and my build.gradle from the app:
apply plugin: 'com.android.application'
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
android {
signingConfigs {
release {
}
}
compileSdkVersion 33
buildToolsVersion '33.0.1'
defaultConfig {
applicationId "com.local.projeto"
minSdkVersion 26
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
ndk {
abiFilters "arm64-v8a"
}
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
jniDebuggable true
debuggable true
renderscriptDebuggable true
minifyEnabled false
}
}
externalNativeBuild {
ndkBuild {
path file('src/main/jni/Android.mk')
}
}
ndkVersion '25.1.8937393'
dependenciesInfo {
includeInApk true
includeInBundle true
}
}
dependencies {
debugImplementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.preference:preference:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'org.jetbrains:annotations-java5:15.0'
}
allprojects {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
my proguard rules have (which made no difference changing this):
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
I also tried to add the Symbols Folder manually on the Debug configuration, but also no success. And it does not seem to be a problem at all on the symbols and compilation, as it is possible to debug the native code. It seems to be just a matter of initialization when debugging. Any ideas?
I have an AR project in unity and i just added Mapbox to the project which immediately caused this error:
What went wrong:
Could not determine the dependencies of task ':launcher:lintVitalRelease'.
Could not resolve all artifacts for configuration ':launcher:debugRuntimeClasspath'.
Failed to transform artifact 'support-v4-25.1.0.aar (:support-v4-25.1.0:)' to match attributes {artifactType=jar}.
>>>> Execution failed for JetifyTransform: C:\Users\EFGH\Documents\GitHub\national-trail\NationalTrail\Temp\gradleOut\unityLibrary\libs\support-v4-25.1.0.aar.
>>>>> Failed to transform 'C:\Users\EFGH\Documents\GitHub\national-trail\NationalTrail\Temp\gradleOut\unityLibrary\libs\support-v4-25.1.0.aar' using Jetifier. Reason: The given artifact contains a string literal with a package reference 'android.support.v4' that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx.. (Run with --stacktrace for more details.)
I have googled this error in so many variations but found nothing relevant, i have deleted the Library folder and rebuilt it but the error persists, i have added android.useAndroidX=true and android.enableJetifier=true in my gradle.properties file but it didn't do anything.
Here is my mainTemplate.gradle:
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.library'
**APPLY_PLUGINS**
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.gms:play-services-maps:17.0.1'
implementation 'com.google.android.gms:play-services-location:18.0.0'
**DEPS**}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
}
lintOptions {
abortOnError false
}
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}**PACKAGING_OPTIONS**
}**REPOSITORIES**
**IL_CPP_BUILD_SETUP**
**SOURCE_BUILD_SETUP**
**EXTERNAL_SOURCES**
And here is my launcherTemplate.gradle: ( i have no idea what the ** SOMEWORD ** means..)
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
apply plugin: 'com.android.application'
dependencies {
implementation project(':unityLibrary')
}
android {
compileSdkVersion **APIVERSION**
buildToolsVersion '**BUILDTOOLS**'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion **MINSDKVERSION**
targetSdkVersion **TARGETSDKVERSION**
applicationId '**APPLICATIONID**'
ndk {
abiFilters **ABIFILTERS**
}
versionCode **VERSIONCODE**
versionName '**VERSIONNAME**'
}
aaptOptions {
noCompress = ['.ress', '.resource', '.obb'] + unityStreamingAssets.tokenize(', ')
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
}**SIGN**
lintOptions {
abortOnError false
}
buildTypes {
debug {
minifyEnabled **MINIFY_DEBUG**
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
jniDebuggable true
}
release {
minifyEnabled **MINIFY_RELEASE**
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
}
}**PACKAGING_OPTIONS****SPLITS**
**BUILT_APK_LOCATION**
bundle {
language {
enableSplit = false
}
density {
enableSplit = false
}
abi {
enableSplit = true
}
}
}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**
I figuered out that some .aar files are being moved from the imported Mapbox asset to a Temp folder, and more specifically from Assets\Mapbox\Core\Plugins\Android into Temp\gradleOut\unityLibrary\libs so it has to be related to the problem somehow.. as shown in the following figure:
I am really stuck on the line Libraries using reflection such as annotation processors need to be updated manually to add support for androidx since this is the only partially-useful line in the error, but i have no idea what it mean to UPDATE the library manually..? update what exactly? and from where? to where? how?
I have a C++ library built for Android, which I package as an Android archive (.aar), along with some Java classes and a Manifest.
Everything is done outside of Android Studio. To package the .aar, I have a directory that contains:
app/src/main/jniLibs/arm64-v8a/: directory with library
app/src/main/java: directory with Java classes
The directory also contains the manifest, and Gradle files.
Here is the build.gradle in the app directory:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.0.2'
}
apply plugin: 'maven-publish'
publishing {
publications {
fooapp(MavenPublication) {
groupId 'com.example'
artifactId 'fooapp'
version "develop"
artifact('build/outputs/aar/app-release.aar')
}
}
repositories {
maven {
mavenLocal()
}
}
}
publishToMavenLocal.dependsOn assemble
By default, all the AAR files contain a stripped version of the library. I do not want the library to be stripped when assembling the Debug version of the AAR.
I found out that I can use packagingOptions to disable stripping, so I tried to add packagingOptions { doNotStrip "**/*/*.so" } under the debug {...} scope of the configuration file.
My problem is that both the debug and release versions of the AAR are then stripped. The two versions of the AAR do seem different, since they don't have the same size (hence have different md5sum).
Where/how can I place my packagingOptions in the Gradle configuration file so that only the release version is stripped? Thanks
The packaging options are specified under buildTypes and then the configuration like Debug or Release etc.
Example:
buildTypes {
debug {
packagingOptions {
doNotStrip '**/*.so'
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
packagingOptions {
doNotStrip '**/*.so'
}
}
}
Note: you added an extra directory /*/ in your specified path.
Previously I had two Android Studio projects. One is using some shared library placed in /src/main/jniLibs (lets call that project bmf). The second project is my actual library which is using that other project (bmf) as an .aar.
If some application is now using the library I had to add the project with the shared library (bmf) as well because the .so files were not packed. Because I want to merge the two projects to one library project I have imported the bmf project as a module. Now if I assemble the library, the .so file of the module is not included. How can I fix that?
My app-module build script looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 15
buildToolsVersion "26.0.2"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
implementation project(':pbJavaBmf')
}
My bmf-module build script looks like:
apply plugin: 'com.android.library'
android {
compileSdkVersion 15
buildToolsVersion "26.0.2"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 15
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
task buildNative(type: Exec, description: 'Pack .so with module') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'V=1',
'NDK_DEBUG=1',
'NDK_LIBS_OUT=../jniLibs'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:18.0.0'
}
I tried to load my project in this new Android Studio 3.0 Canary 1.
It was running perfectly in my previous Android Studio Version 2.4 preview 7
This is the error I am facing:
Error:Could not resolve all dependencies for configuration ':sample:devCompileClasspath'.
Project :sample declares a dependency from configuration 'devCompile' to configuration 'dev' which is not declared in the descriptor for project :library.
My gradle configs are as below:
Project Level Build Gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
classpath 'com.google.gms:google-services:3.0.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
}
Library Module Gradle:
apply plugin: 'com.android.library'
apply plugin: 'checkstyle'
android {
publishNonDefault true
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionName project.VERSION_NAME
versionCode project.VERSION_CODE.toInteger()
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'AUTHORS'
exclude 'NOTICE'
}
buildTypes {
debug {
debuggable true
}
dev.initWith(buildTypes.debug)
staging.initWith(buildTypes.debug)
release {
minifyEnabled false
shrinkResources false
}
}
}
repositories {
flatDir {
dirs 'libs'
}
mavenLocal()
jcenter()
}
def ANDROID_SUPPORT_VERSION = "25.3.1"
def OK_HTTP3_VERSION = "3.6.0"
def GLIDE_VERSION = "3.7.0"
def GSON_VERSION = "2.8.0"
def AWS_KINESIS_VERSION = "2.4.2"
def PLAY_SERVICE_VERSION = "10.2.4"
dependencies {
compile(name: 'library-release', ext: 'aar')
compile "com.android.support:appcompat-v7:$ANDROID_SUPPORT_VERSION"
compile "com.android.support:design:$ANDROID_SUPPORT_VERSION"
compile "com.android.support:cardview-v7:$ANDROID_SUPPORT_VERSION"
compile "com.squareup.okhttp3:okhttp:$OK_HTTP3_VERSION"
compile "com.squareup.okhttp3:okhttp-urlconnection:$OK_HTTP3_VERSION"
compile "com.squareup.okhttp3:logging-interceptor:$OK_HTTP3_VERSION"
compile "com.google.code.gson:gson:$GSON_VERSION"
compile "com.google.firebase:firebase-messaging:$PLAY_SERVICE_VERSION"
compile "com.google.android.gms:play-services-location:$PLAY_SERVICE_VERSION"
compile "com.github.bumptech.glide:glide:$GLIDE_VERSION"
checkstyle('com.puppycrawl.tools:checkstyle:7.6.1')
compile "com.amazonaws:aws-android-sdk-kinesis:$AWS_KINESIS_VERSION"
}
apply plugin: 'com.google.gms.google-services'
task checkstyle(type: Checkstyle) {
showViolations = true
configFile file("config/checkstyle/checkstyle.xml")
description 'applies the checkstyle config to the java files'
source 'src/main/java'
include '**/*.java'
exclude '**/gen/**'
// empty classpath
classpath = files()
}
preBuild.dependsOn('checkstyle')
App Module Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.sample.and"
minSdkVersion 19
targetSdkVersion 25
versionName project.VERSION_NAME
versionCode project.VERSION_CODE.toInteger()
android.defaultConfig.vectorDrawables.useSupportLibrary = true
}
buildTypes {
debug {
debuggable true
minifyEnabled false
shrinkResources false
}
dev.initWith(buildTypes.debug)
dev {
applicationIdSuffix ".dev"
}
staging.initWith(buildTypes.debug)
staging {
applicationIdSuffix ".staging"
}
release {
shrinkResources false
minifyEnabled false
}
}
}
repositories {
flatDir{
dirs '../library/libs'
}
mavenLocal()
jcenter()
}
configurations {
releaseCompile
stagingCompile
devCompile
}
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
releaseCompile (project(path: ':library', configuration: 'release')) {
transitive = true
}
stagingCompile (project(path: ':library', configuration: 'staging')) {
transitive = true
}
devCompile (project(path: ':library', configuration: 'dev')) {
transitive = true
}
}
Did anyone face the same issue ?
Have a look at the migration tips:
Use Flavor Dimensions for variant-aware dependency management
As it states:
Plugin 3.0.0 includes a new dependency mechanism that automatically
matches variants when consuming a library. This means an app's debug
variant automatically consumes a library's debug variant, and so on.
It also works when using flavors—an app's redDebug variant will
consume a library's redDebug variant. To make this work, the plugin
now requires that all flavors belong to a named flavor dimension —even
if you intend to use only a single dimension. Otherwise, you will get
the following build error:
Error:All flavors must now belong to a named flavor dimension.
The flavor 'flavor_name' is not assigned to a flavor dimension.
To resolve this error, assign each flavor to a named dimension, as
shown in the sample below. Because dependency matching is now taken
care of by the plugin, you should name your flavor dimensions
carefully. For example, if all your app and library modules use the
foo dimension, you'll have less control over which flavors are matched
by the plugin.
// Specifies a flavor dimension. flavorDimensions "color"
productFlavors {
red {
// Assigns this product flavor to the 'color' flavor dimension.
// This step is optional if you are using only one dimension.
dimension "color"
...
}
blue {
dimension "color"
...
}
flavorDimensions "mode"
productFlavors {
dev {
// Assigns this product flavor to the "mode" flavor dimension.
dimension "mode"
versionName "1.2"
versionCode 02
}
uat {
// Assigns this product flavor to the "mode" flavor dimension.
dimension "mode"
versionName "1.2"
versionCode 2
}
live {
// Assigns this product flavor to the "mode" flavor dimension.
dimension "mode"
versionName "1.0.1"
versionCode 01
}
}
This is working for me !!
In your case you should just make a flavorDimensions variable and assign the value inside the dev block
flavorDimensions "anyvalue"
dev.initWith(buildTypes.debug)
dev {
dimension "anyvalue"
applicationIdSuffix ".dev"
}
This should help .