I'm trying to use Checkstyle on an Android project. I figured Googles java coding conventions would be good to use. I'm getting an error when parsing this file:
https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml
I've looked this error up on stack overflow and it has come up once before, How to compile project with Google Checkstyle rules with gradle?
It seems the error is an older version of checkstyle is pulled down when using gradle. So my question is, is there just an older checkstyle configuration file I can use that's made for the current version of checkstyle pulled down by gradle? Should I even be using Googles java guidelines for an Android project? Is there a better default file to work with? I really don't want to import a new version of checkstyle into my project as mentioned in the answer of the other SO question.
You should always specify the exact version of Checkstyle that you want to use. The Checkstyle guys often make breaking changes which would fail your build unless you set a specific fixed version. For example:
checkstyle {
configFile file('downloaded_google_checks.xml')
toolVersion '6.9' // set Checkstyle version here
showViolations = true
}
Then, you can also use the right configuration file for your version, for example: https://github.com/checkstyle/checkstyle/blob/checkstyle-6.9/src/main/resources/google_checks.xml. Note the version number in the URL - this can be adjusted to the version you selected in your Gradle config.
Do not use the latest configuration file from the master branch, as this matches the current code on the master branch (which is not released yet).
The above allows you to adjust the configuration as necessary. If you are certain that you want the original rule file, you may also follow #BenMane's suggestion from his comment, which is to reference the bundled google_checks.xml directly.
Related
My project is using now Version Catalog for all the Gradle modules, and now using the type safe declaration of dependencies in the build.gradle file I don't get any suggestions from the IDE when there's an update of a specific dependency.
What would be the best approach to know if there's an update of a dependency, instead of checking manually one by one?
My recommendation is to use the gradle-versions-plugin or this extension of it (https://plugins.gradle.org/plugin/se.ascp.gradle.gradle-versions-filter). Both add an additional gradle task dependencyUpdates to your project that will tell you which version updates are available.
Also works fine in combination with the new versions catalog feature you mentioned. I am using it too.
How do I specify the version used for Android Lint? From the lint report: <issues format="5" by="lint 3.5.3">
Lint is a part of ADT(Android Development Tools) and more specifically it depends on the Android Gradle Plugin Version. You cannot change Lint version independently from gradlePluginVersion. When you change gradlePluginVersion, Lint version will be changed automatically to the corresponding one from current version of the plugin.
If you want to disable some checks or write your own rules you may check this. Also you may create your own 'Lint' modules using "com.android.tools.lint:lint-api:$lintApiVersion"
and "com.android.tools.lint:lint-checks:$lintApiVersion" compileOnly dependencies from here
Hope it helps
Hi I'm fairly new to android development. I have a question regarding the Gradle version and the distribution url in gradle-wrapper.properties
classpath "com.android.tools.build:gradle:$gradle_version"
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
So every once a while I need to update gradle version (because android studio requires it). How do I find the new version number. Sometimes I need to update the gradle wrapper too, so how do I find the new distributionUrl that works with new gradle version?
It feels no one talk about this part of the android development and there isn't good documentations especially after google io
The Gradle Wrapper version can be changed by executing ./gradlew wrapper --gradle-version=4.9 as described here. This will automatically update the distributionUrl in gradle-wrapper.properties. If you want to manually set the distributionUrl, you can rely on the URL conforming to the same pattern as in your example. In other words, you can simply change the part of the URL that specifies the version (4.4 in your example) to the desired version. Check the repository, you will see that all releases are available at URLs that conform to the pattern https://services.gradle.org/distributions/gradle-X.Y-DISTRIBUTIONTYPE.zip (with capitalization indicating variable parts). The list of releases are also available in more reader-friendly format on the "Releases" page of the Gradle Website.
Previously my gradle used to look like this and worked fine (apart from few registered bugs)
implementation 'com.dji:dji-sdk:4.3.2'
Now, after changing to
implementation 'com.dji:dji-sdk:4.4.0'
the Camera and other files cannot be recognized anymore. I am attaching a screenshot of the unrecognized imports.
However when I am trying to add
//dji-drones-sdk
implementation 'com.dji:dji-sdk:4.4.0'
provided 'com.dji:dji-sdk-provided:4.4.0'
I am getting "could not download dji-sdk-provided.jar"
Screenshot attached
All the examples and github codes are in version 4.3.2. Can anyone help me out?
Here is the link to the dji sdk
I have found the issue. After Gradle 3.4, the "provided" is replaced by "compileOnly"
I quote,
Gradle adds the dependency to the compilation classpath only (it is not added to the build output). This is useful when you're creating an Android library module and you need the dependency during compilation, but it's optional to have present at runtime. That is, if you use this configuration, then your library module must include a runtime condition to check whether the dependency is available, and then gracefully change its behavior so it can still function if it's not provided. This helps reduce the size of the final APK by not adding transient dependencies that aren't critical. This configuration behaves just like provided (which is now deprecated).
Hence using compileOnly in place of provided will do the trick.
Here is a link to the gradle changes documentation
Let say I have added Facebook and Twitter dependencies in my app.
com.facebook.android:facebook-android-sdk:4.22.1
com.twitter.sdk.android:twitter:2.1.0
When i look at Gradle tree, They come up with bunch of other transitive dependencies.
Now If Facebook uses com.android.support:support-annotations:24.1.1 and twitter uses com.android.support:support-annotations:25.0.3
Then which version gradle will use.
In gradle tree, It shows -> in front of older version of dependency. I learnt that this means gradle will use the newer version, and will not use the older version.
But this can be a problem, because some libraries are meant to run on the specific versions, and i have faced this problem.
In one of article i found out how npm manages these dependencies conflicts, but i am still unsure how gradle will manage between different version of same library.
You can't have different versions of the same library inside an apk.
As you mentioned, by default, Gradle puts the newest one to the build. If you want to specify a concrete version of the library that should be used in your project, you can add a direct compile (or implementation / api for Android Gradle Plugin v3+) statement with a required version to get one.
Also, you can force version using a special syntax, but it can lead to some problems later. You can find more information about version conflicts resolution in this post