Sonar not analyzing Android xml files - android

I'm adding a job in Jenkins to analyze an android project, but I can't get it to take into account the xml files (in res/ and subdirectories).
My sonar.properties:
# required metadata
sonar.projectKey=AndroidProj
sonar.projectName=AndroidProj
sonar.projectVersion=1.0
# path to source directories (required)
sonar.sources=src
sonar.binaries=bin/classes
# The value of the property must be the key of the language.
sonar.language=java
sonar.sourceEncoding=UTF-8
sonar.profile=Android Lint
What this gives me in the SonarQube web UI is only the java files (and indeed sonar.language=java should be an indication of this), so how could I go to get a Lint check on the xml files?
Setting sonar.language=xml doesn't go well with sonar.profile=Android Lint.

As SonarQueb does not correctly support multi-language projects, the Android plugin indeed only reports issues on Java files.
Our goal is obviously to report also issues on XML files as soon as the multi-language support is ready. You can vote for the following ticket and watch it to know the progress: http://jira.codehaus.org/browse/SONAR-926

For anyone who stumbled upon this issue with later versions of SonarQube (I am using 5.3), you need the following things:
Android Plugin installed
XML Plugin installed
remove the "sonar.language" property so that sonar can detect the languages used there by default
add your res folder to your "sonar.sources" property. Mine looks like this:
property "sonar.sources", "src/main/java,src/main/res"
(defined in a sonarqube properties block in gradle).

Related

Android: Library (AAR) module build.gradle coding

I have a project tree (a Solution in terms of Visual Studio) with some Executable and AAR library modules.
I need to get something like this in their build.gradle files..
buildTypes {
release {
//if not exist :- create extra folder in standard or customised output folder
//with the name 'Release'
//say builder to put the release build version into this folder with
//names ModuleName.aar or .apk
}
debug {
//if not exist :- create extra folder in standard or customised output folder
//with name 'Debug'
//say builder to put the debug build version into this folder with
//names ModuleName.aar or .apk
}
}
I've spent 2 days looking for a documentation how to do that.. I found just fragmentary parts of some specific settings, which ain't interesting now.
Actually, I want to get the same behaiviour of the compiler and builder as it's in Visual Studio
ProjectBuildDir\Debug\ModuleName.aar
ProjectBuildDir\Release\ModuleName.aar
Please, if you know, this would be very good to share that knowledge..
Otherwise.. I think I'll spend whole week without success.. or refer to full documentation of how to program gradle build code.
UPD: I've seen such kinds of solution, but it makes my project structure unreadable by AS. It denies to sync project with its gradle.. it hides Tool window "Build variants".. it hangs on AS itself.. :)
Maybe it happens because it's applied to Module (AAR library)?
I don't know.. I just also unable to compile and build the release version :)
I can see debug but whem I change variamt in that Tool Window in front of the AAR-Module name - then run Rebuild (Clean and Sync..) - there is no any realease in the output folder.
And I can't find the description of this meta language..
I use the AAR as Android UserControl library - extended View.. because it's handy to develop it as separate module.. simply faster..
I am the Android-kid, but MicroSoft-man :) need to see the logic of the project meta data language..

How do I use this file from Github on Android Studio?

I understand this might be an extremely obvious and ridiculous question to ask, but please excuse me as I'm a beginner. I want to integrate this file into my project so I can call its methods:
https://github.com/RomainPiel/Shimmer-android
The question is, what do I do with it? Is it considered a "module", "library" or "file"? Should I manually copy the source files and create new classes in my project, and then call the methods from there? This would be the most straight-forward but in the "how to use" section in that package, it was mentioned "compile 'com.romainpiel.shimmer:library:1.4.0#aar'"
What I tried:
I downloaded the file as a .zip and then File->New->Import Module then navigated to the unzipped file. I believe I'm then supposed to add "compile 'com.romainpiel.shimmer:library:1.4.0#aar'" so I went to the gradle file to try to add it.
There are two: build.gradle (Module:app) and (Project:ProjectName).
I've tried adding to either and\or both and got this error: (Error:9,0) The project 'ProjectName' may be using a version of Gradle that does not contain the method. Did I do something wrong? Is it supposed to be this easy?
I would be extremely grateful to anyone who can point me in the right direction :)
You have three option
Using the GitHub Desktop you can clone the project and open it like a local project. Every change you make will be tracked. You can then commit and push using the GitHub Desktop. It's all UI and simple to use.
https://desktop.github.com
On Android Studio, when you open it, you'll see this, select GitHub and continue by adding your credentials.
You can then commit and push directly from that.
Using the terminal / command line.
If you are new, I recommend the first. It's simple to use and you get a hang of using it as it is the same steps with any project on any IDE you use.
Note: Downloading it as zip and then using it a bad idea because you're making it difficult on yourself because you can't keep track of changes and you'll have to re-upload everything every time. Which defeats the purpose of version control
If that GitHub account is not yours, then you'll have to fork the project, this way you'll have a separate version of the code on you GitHub on which you can modify. If it is yours then you're good.
Typically, you do not want to include external source code manually. This inhibits your build tool's (i.e. Gradle's) ability to manage that source code. It's very easy in Gradle to, say, set the version (like you have done by specifying "1.4.0") and then later remind yourself what version you have by merely looking at your build.gradle file. However, how would you go about doing that with raw source code? Typically developers do NOT put the version number of the source code in the actual source code - that's what they use their version control system (e.g. git) for, usually with tags.
Another aspect of Gradle is downloading and caching (and compiling) the external project for you. So that's nice.
With that said, you typically want to put that "compile..." line in your module's build.gradle file. Not the Project's build.gradle.
A module corresponds to your application (or library) that you are building or using. Some project's have multi-module configurations, where one module acts as a dependency for another (or several others). A Project in gradle is more of a 'meta' configuration that you can apply to all of your modules. The gradle docs recommend you focus on your module's configuration first and adjust the Project's configuration only if you have a specific need and reason to do so.
For the error you mentioned, you might have some unnecessary configurations in your build.gradle file, or the tool version numbers might not reflect what's on your system - if you copied and pasted from the internet, you might want to correct this by letting your IDE generate that file (the brute-force approach would be to create a new project entirely, and use its build.gradle files as a reference). Before you do that, you might want to check if your IDE provides any warnings inside that file.
You have to add the dependency to your module's gradle file.
There are two gradle file present in an android project. One is the project gradle and the second is the module gradle for each individual module.
You just have to copy the given
compile '......' in the dependency block.

Proper configuration for "sonar.libraries" in a modern Gradle Android project

What I want to achieve:
In sonar it is possible to track third party dependencies used throughout Projects by setting the property "sonar.libraries" and perhaps there are more benefits (such as detecting which violations are caused by external libraries?)
What I tried to do:
I set the value to build/intermediates/pre-dexed/debug/*.jar but this seems to have little effect.
Question:
Since it is no longer needed to use the "libs" folder for third party dependencies, what is the recommendation for the property called "sonar.libraries"?
We need to implement special processing when an Android project is detected. Correctly setting sonar.java.libraries is one of the requirements. A ticket already exists, feel free to vote or provide a pull request.
https://jira.sonarsource.com/browse/SONARGRADL-6
Update: we have released version 2.1 of the plugin (currently RC2) that natively supports Android projects. Properties sonar.java.[test.]binaries and sonar.java.[test.]libraries will be automatically populated.
The pre-dex folder also seemed to me to be the perfect candidate. Unfortunately, if you look into the jars in this folder, you'll see they contain no compiled class, but dex files. A dex file being a "dalvik executable", it's Android material, and Sonar can't do anything of it.
I managed to reference some of my dependencies, by declaring build/intermediates/exploded-aar/**/*.jar in the sonar.libraries property.
With this line you'll see all the "android librairies" (aar) that your project depends on. I've not yet managed to track all the other plain java libraires (jar)

Android adding custom lint rule to the project (git)

I needed a custom lint rule, so created one using the steps from here
All is working ok, the custom rule is now checked by lint. However, I have added the custom rule .jar to /.android/lint path. But this means that this rule is checked only for me locally.
The location of the .android directory is typically the home directory; lint will search in $ANDROID_SDK_HOME, in ${user.home} (the Java property), and in $HOME. (Somebody asked about this; Lint basically calls the general Android tools method to find the "tools settings directory", used for emulator snapshots, ddms configuration, etc. You can find the relevant code for that here: https://android.googlesource.com/platform/tools/base/+/master/common/src/main/java/com/android/prefs/AndroidLocation.java )
How can I add the .jar file to the project such that all the people working on it will have this lint rule checked? Searched for an answer but didn't find any clues...
The new AAR format allows to compile and bundle custom lint rules which is perfect for distributed working OR CI environments, like mentioned here [1].
Another suitable solution is to have your custom lint rule as module/project dependency within your application project.
https://engineering.linkedin.com/android/writing-custom-lint-checks-gradle
You did not found you r answer yet since as far as i know you cannot add external files to git unless they are subtree/submodule which is not the request in your case.
Again: there is no way to do it in GIT.

AndroidManifest.xml encoding is not readable after gradle assemble task

I wanted to explore the generated AndroidManifest.xml of my .apk and I realised that the format was not readable.
Both debug and release apks contain the encoded manifest file. How is that possible when progaurd is disabled?
Does Gradle modify the encoding during assemble process?
Is there anyway to disable that feature?
How is that possible when progaurd is disabled?
ProGuard has nothing to do with it. XML (manifest and resources) is converted into a "binary XML" format as part of the build process.
Does Gradle modify the encoding during assemble process?
Not specifically. Creating this binary XML is part of the build tools in general, whether invoked from Gradle, Ant, Eclipse, or whatever.
Is there anyway to disable that feature?
No. There are tools available that can decompile an APK, and some of those will convert the binary XML back into a text representation. Or use aapt dump badging. Or, use an on-device inspector, like App Browser.
The App Browser on-device inspector mentioned by Mark doesn't display the Android manifest very well (since it doesn't resolve resource references). There's a much better view given by App Detective

Categories

Resources