I'm using Kover to get coverage on kotlin and want to share it with sonar, configuration is like this:
plugins {
...
id "org.jetbrains.kotlinx.kover" version "0.4.2"
id "org.sonarqube" version "3.3"
}
sonarqube {
properties {
property "sonar.sourceEncoding", "UTF-8"
...
property "sonar.coverage.jacoco.xmlReportPaths", "${project.buildDir}/reports/kover/report.xml"
}
}
project.tasks["sonarqube"].dependsOn "koverReport"
Now, the HTML report of Kover says I have 33% of coverage meanwhile Sonar shows a 10% coverage. What could be the problem?
The simple answer is that they are computed differently: https://community.sonarsource.com/t/sonarqube-and-code-coverage/4725 .
Butterknife 8.8.0 introduced the new processor option butterknife.debuggable (link to changelog). By default, it's true. Where do I set it to false in my build.gradle file? I tried placing it in my defaultConfig, but I keep getting the error:
Could not get unknown property 'butterknife'...
Looks like Butterknife mirrors the debuggable attribute of your current config. So setting debuggable inside your defaultConfig or other build type should also set butterknife.debuggable.
EDIT: My initial answer was incorrect. Add this to your Gradle build type to modify the butterknife.debuggable flag:
javaCompileOptions.annotationProcessorOptions.arguments['butterknife.debuggable'] = 'false'
I try to integrate my android app with a Travis CI. My app need an api key, that shouldn't be posted in repo. So, i put my api key in global gradle properties file ~/.gradle/gradle.properties:
MY_SECRET_API_KEY="aaaabbbcccdddeeefff"
Then I read this value in app/build.gradle file (which is in public repository) and set it as buildconfig field:
apply plugin: 'com.android.application'
android {
// ...
buildTypes.each {
it.buildConfigField "String", "API_KEY", MY_SECRET_API_KEY
}
// ...
}
and use this api key in app code by accessing to BuildConfig.API_KEY.
I get following error message from Travic CI:
Could not find property 'MY_SECRET_API_KEY' on com.android.build.gradle.AppExtension_Decorated.
Use Travis' environment variables; more specifically use encrypted variables so that the values of secure variables are always masked in the build output. You read Tavis env variables in the gradle script as System.getenv('key') though. It is cleaner to use environment variables on the local end as well. If you want to still use gradle.properties, you could do something like this:
hasProperty('secret_api_key') ? secret_api_key: System.getenv('secret_api_key')
To set Travis env variables, see here:
I am trying to get the variable defined in a 3rd party library (fabric) to do a condition based on whether Crashlytics is enabled or not.
ext.enableCrashlytics = true
http://support.crashlytics.com/knowledgebase/articles/202938-gradle
The variable can be configured in buildTypes or in flavors but I can't find a way to access it elsewhere in my build.gradle
I tried several things without any luck.
allprojects.getProperties().get("enableCrashlytics")
project.enableCrashlytics
project.ext.enableCrashlytics
allProjects.ext.enableCrashlytics
Anyone tried that before? The context I'm trying to do this is to write the fabric.properties file based on if it is enabled or not.
android.applicationVariants.all { variant ->
...
//create fabric.properties
...
}
You can define a property in your top-level build.gradle:
ext {
myproperty = 12
}
Or an array:
ext {
myarray = [
name0 : "xx",
name1 : "xx"
]
}
Then in each module you can use somenthig like:
rootProject.ext.myproperty
rootProject.ext.myarray.name0
I know this question is old but I stumbled upon it while attempting to do a similar thing.
After trial and error and reading through the build system source I figured it out.
variants.all { variant ->
println("${variant.name.capitalize()}")
println(variant.getBuildType().myFoo)
println("------")
}
With this you'll be able to read the ExtraPropertiesExtensions from the different variants.
My output:
Debug
true
------
Release
true
------
Something
false
------
Here are the files I looked through to figure it out:
ApplicationVariantImpl and DefaultBuildType
project.hasProperty 'propName'
(parens optional when possible in groovy, prefer 'String' over "GString")
Background
I've recently migrated my app to Android-Studio. I had some issues doing so, but I got over them eventually.
The problem
For some reason, on Android Studio, when I try to sign an APK, I get a lot of errors that look like this:
Error:(16) Error: "..." is not translated in "de" (German), "el" (Greek), "iw" (Hebrew) [MissingTranslation]
(where "..." is a string)
At the bottom, after a lot of errors of this kind, I see this:
Error:Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
The question
I'm not sure what's wrong and how I can fix it. On Eclipse I did it very easily. Missing translations shouldn't stop me from signing an APK...
To me it seems as if Lint is preventing the exporting of the APK, and that the reason is that I didn't translate all of the strings. Is that true?
Can anyone please help me? How can I fix this, so that Lint will show me just warnings instead? or a confirmation dialog if I'm sure I want to do it?
The cleanest way to solve the problem is to disable Lint checks of missing translations for release builds only.
To do so add "disable 'MissingTranslation'" to your build.gradle file as shown below:
android {
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
}
}
}
To me it seems as if Lint is preventing the exporting of the APK, and
that the reason is that I didn't translate all of the strings. Is that
true?
Yes. Default option is lintOptions.abortOnError = true
Can anyone please help me?
You should open the build.gradle file located at the main project module, or the generic folder if you do not have a module. Then add the suggested lines:
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
Some Lint warnings are by default turned to studio as errors, I don't actually know why, but in terms of translations I guess that is a way to "stop" you publishing an app that the translation is incomplete due to a last minute additions of some texts.
With the lintOptions checkReleaseBuilds abortOnError you set the checking of Lint not to run for release versions and also not stopping if an "error" is found. Below I explain where the Lint errors settings can be found, so if you want to go further you can go one step forward and read them one by one. Some of them provide helpful instructions for code optimizations.
How can I fix this, so that Lint will show me just warnings instead?
or a confirmation dialog if I'm sure I want to do it?
There is also an option at the Android Studio settings to change any Lint error to Lint warning, but I never test that. I usually turn to the gradle solution.
The option is located at Settings > Inspections > Android Lint. For easy find open Settings and at the search (located at the top) type Lint translation there you can change the translation options appear at the left from errors to warnings.
An other option if your error strings never going to be translated is to add at your XML string files tools:ignore="MissingTranslation" either at the root item or at each non-translatable string.
Simple way to solve this Error
Just add following Code To do add "disable 'MissingTranslation'" to your build.gradle file as shown below:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
OR You can also Add this:
android {
buildTypes {
release {
lintOptions {
disable 'MissingTranslation'
}
}
}
}
You could try to open "Translations Editor" and set the string "..." as "Unstranlatable".
You also must remove all translations of this string.
FWIW: If you don't plan on supporting other languages, then you don't need to disable the lint checks at all. Sometimes your project setup (or a library you're importing) may have accidentally - or intentionally - included a config to support additional languages by declaring a values- folder for that language like this for instance:
<your project source folder>/main/res/values-ar
This was the case for me so I simply removed the folder. But if you have no control over the offending library then one choice is to disable lint abortOnError as indicated in the accepted answer, or find a way to exclude 'library-imported' folders somehow. For the latter option you can start here
there is many solution but i tried
<string name="hello" translatable="false">hello</string>
It's the ignore attribute of the tools namespace in your strings file, as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingTranslation" >
<!-- your strings here; no need now for the translatable attribute -->
</resources>
and from the Gradle
release {
lintOptions {
disable 'MissingTranslation'
}
}
and
android {
lintOptions {
disable 'MissingTranslation'
}
}
Working
buildTypes {
release {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}