How to find which checkstyle version gradle is using? - android

In my gradle file I have:
apply plugin: 'checkstyle'
I'm trying to create my own checkstyle rules. For this reason I have added a dependency to my gradle file.
dependencies {
checkstyle 'com.puppycrawl.tools:checkstyle:8.2'
}
I am trying to extend "Check" class of checkstyle. But there are a lot of version of checkstyle and I dont know which one is used by gradle.
How can I find the exact version number of checkstyle which gradle is using?

There are three ways I can think of right now, least attractive first:
You can look into the Gradle source code.
You can check the Checkstyle Compatibility Matrix (column L, yellow cells).Both say that from Gradle 3.3 onwards, the default Checkstyle version is 6.19; before, it was 5.9. Only Gradle versions prior to 2.4 used even older versions of Checkstyle.
But the recommended way is to choose the Checkstyle version explicitly, by specifying it in your build.gradle file:
checkstyle {
configFile file('your/checkstyle.xml');
toolVersion '8.2'; // your choice here
}
This is better than relying on the default version, because you can use much newer versions of Checkstyle, and your Checkstyle setup won't break when you update Gradle.

You can check the current value of checkstyle.toolVersion by writing this in your build.gradle file and reloading your gradle project
plugins {
id 'java'
id 'checkstyle'
}
println checkstyle.toolVersion

Provide a better solution, and you can refer the to the examples of configuration file from checkstyle source codes without worrying about compatibility.
Simply run gradle dependencies | grep checkstyle
Then get corresponding checkstyle sources here to refer the configuration samples: https://github.com/checkstyle/checkstyle/releases

with out-of-box apply plugin: 'checkstyle', the checkstyle would use v6.19.
Downloaded dependencies:
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.19/checkstyle-6.19.pom
Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.3/antlr4-runtime-4.5.3.pom
Download https://repo1.maven.org/maven2/org/antlr/antlr4-master/4.5.3/antlr4-master-4.5.3.pom
Download https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.pom
Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/41/commons-parent-41.pom
Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/6.19/checkstyle-6.19.jar
Download https://repo1.maven.org/maven2/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar
Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.5.3/antlr4-runtime-4.5.3.jar
after dependencies { checkstyle 'com.puppycrawl.tools:checkstyle:8.2' }, the downloaded dependency list:
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/8.2/checkstyle-8.2.pom
Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7.pom
Download https://repo1.maven.org/maven2/org/antlr/antlr4-master/4.7/antlr4-master-4.7.pom
Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.4/commons-cli-1.4.pom
Download https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-4/Saxon-HE-9.8.0-4.pom
Download https://repo1.maven.org/maven2/org/antlr/antlr4-runtime/4.7/antlr4-runtime-4.7.jar
Download https://repo1.maven.org/maven2/net/sf/saxon/Saxon-HE/9.8.0-4/Saxon-HE-9.8.0-4.jar
Download https://repo1.maven.org/maven2/commons-cli/commons-cli/1.4/commons-cli-1.4.jar
Download https://repo1.maven.org/maven2/com/puppycrawl/tools/checkstyle/8.2/checkstyle-8.2.jar

Related

Errrors, when configuring react-native project (building gradle) with android studio. I want to build gradle scripts for using firebase with my app

I ran into this problem after i updated android studio and the gradle version. Here's what i did step by step:
First i got the following error:
Build Gradle Error Could not get unknown property 'compile'
I checked stackoverflow and it said that changing "compile" with "implementation" would solve the problem, and so i did that.
Another issue was that maven was deprecated. So i used, maven-publish instead of maven.
Now i am getting the following error:
12:24 PM Gradle sync failed: Could not find method uploadArchives() for arguments [build_a5ye7ixpcm9qfmol93kt3ucl1$_run_closure4#73b8042a] on project ':expo-application' of type org.gradle.api.Project. (17 s 537 ms)
In this part of code in build.gradle(:expo-application):
uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
repository(url: mavenLocal().url)
}
}
}
I am not really familiar with android studio or java. I just use Android Studio for configuring react native apps for android. Can someone please help me resolve these issues..
Thank you
As of Gradle 7.0, compile has been removed in favor of api. When you changed compile to implementation, you effected the transitive properties of the libraries. I'm not sure where you read that changing compile to implementation was the correct answer, but it isn't. api is a much closer approximation to compile. This chart gives a fairly easy to understand explanation of why this is. You should change the implementation to api and make sure you are using the java-library plugin instead of the java plugin. This should allow gradle to see the UploadArchives method. However, this wil cause a new issue.
As of Gradle 6.0, UploadArchives is also deprecated along with the maven plugin. You should consider using the maven-publish plugin instead. This will ensure your build continues to work in future Gradle releases.
So, to summarize, make sure your plugins look like this
apply plugin: 'java-library'
apply plugin: 'maven-publish'
and update your code to use publishing instead of UploadArchives. More information on this can be found in the current Gradle user guide here.
Alternatively, you can downgrade your gradle version to something before 7.0 and just ignore all the deprecation warnings. The choice is yours.

Disable Google Services Gradle plugin for specific flavour

The usage of Google Services requires the use of this Gradle plugin:
apply plugin: 'com.google.gms.google-services'
This thread on the Gradle forum has lead me to conclude that you can't selectively enable or disable a plugin, meaning that is not an option. I've tried a number of solutions offered by older threads involving conditionals surrounding the apply plugin statement and none of them work now.
The plugin itself is configured by a google-services.json that Google generates and is placed into the project directory. I'm aware that you can have different configurations for each flavour by having multiple google-services.json files, but what are we meant to do for build flavours that we explicitly want to not use Google Services (e.g. for targeting devices that do not have Play Services installed)? Blank files or dummy JSON files don't work as the plugin will refuse to accept it.
So the only solution that I can think of would be to manually disable the plugin (comment out that line) each time I want to test/build my flavour. Surely there has to be a better way to control how the plugin works?
I finally got a version to work. Tested with gradle 4.6, build tools 3.0.1, google-services plugin 3.1.1
apply plugin: 'com.google.gms.google-services'
android.applicationVariants.all { variant ->
if (variant.name == 'someVariantNameYouDontwantFirebase') {
project.tasks.getByName('process' + variant.name.capitalize() + 'GoogleServices').enabled = false
}
}

Reusing the same code across multiple Android Studio projects

I have some code I'd like to use across multiple different projects. Let's say it's some e-commerce code that handles things like payments and shopping carts.
It seems inefficient and dangerous to copy-paste everything across different projects. And if I add one feature or fix one bug in the core e-commerce module, I'd like that change to be reflected in other projects using it too.
I would also like to re-use some of the Activities, Fragments, Adapters too.
What is a good approach to this?
When we have a library project that needs to be shared to every project on a local computer, we can make use of Maven.
A. Here the step in your library that we will you for the project:
Make a library project from Android Studio.
Add Gradle Android Maven plugin to root build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Add apply plugin for step 1 in your library build.gradle. (NOT root build.gradle):
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
Add the following after the apply plugin, this line to determine your library when adding to project:
group = 'com.yourpackage.yourlibrary'
version = '1.0'
Add the following code in your settings.gradle:
rootProject.name = 'yourlibrary'
Then publish it to your local maven with:
./gradlew install
Or you can use gradle option in Android Studio.
Your library will be installed in $HOME/.m2/repository. Remember that to use the library you need to add like this:
Groupid:artifactid:versionid
Artifactid will be package name of your library.
B. Here the step in your Project which using the library:
Add the following code in your root build.gradle:
mavenLocal() // for local maven.
This for getting the local library maven that we have installed in step A
Then in your app project.gradle, add compile for the library:
compile 'com.yourpackage.yourlibrary:yourlibrary:1.0'
Read more:
Gradle: How to publish a Android library to local repository
https://github.com/dcendents/android-maven-gradle-plugin
https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
From my Knowledge 1. As others said try creating your own Module or Library and use it where ever you need 2.Use Version Control Tools Like Git(If your code changes it will be refleted in your git account)

How to obtain firebase libraries, e.g. firebase-messaging-9.4.0.jar

I am trying to do an automated android build in a local network segment (ie. without access to public jcenter or maven repositories). In order to do that I need to provide all dependencies in a local maven repository which is referenced from the root build.gradle. (NB: if I use the android-maven-plugin instead of gradle the situation is the same).
This works fine, only I have difficulties locating the firebase libraries like firebase-core-9.4.0.jar or firebase-messaging-9.4.0.jar. According to the gradle console output they are searched in a location
<server>/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar
This location does not exist in the public jcenter or maven repositories.
Does anyone know where to find them?
edit: I have observed Android Studio on empty caches using Wireshark (using http for the jcenter repository). The results are rather mysterious. It issues a GET request for
http://jcenter.bintray.com/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar
This request is redirected to
http://repo.jfrog.org/artifactory/libs-release-bintray/com/google/firebase/firebase-messaging/9.4.0/firebase-messaging-9.4.0.jar?referrer
The latter GET request results in HTTP 404 as the repo.jfrog.org repository has no content in the firebase-messaging/ directory. However, Android Studio extracts the jar files in the build directory and continues to build the project.It is unclear, where the jar files come from.
You can show all librarys in the oficial support.
https://firebase.google.com/docs/android/setup
Found this link, hope this help
https://github.com/unity-plugins/Google-Firebase-SDK
According to this, you should add to you build.gradle:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:3.1.1'
and that to your app/build.gradle:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
compile 'com.google.firebase:firebase-core:11.8.0'
// Getting a "Could not find" error? Make sure you have
// the latest Google Repository in the Android SDK manager
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
Update 2020
Firebase aar are now available on maven repository at https://mvnrepository.com/artifact/com.google.firebase
For example, firebase-core aar is at https://maven.google.com/com/google/firebase/firebase-core/17.4.4/firebase-core-17.4.4.aar

Android Studio fetching an old artifact

I'm using Android Studio to download an artifact that's available within an internal maven repository. At times Android Studio fails to fetch the latest Snapshot which results in compilation errors. Is there any workaround for this problem ?
From the Gradle forums at http://forums.gradle.org/gradle/topics/how_to_get_gradle_to_download_newer_snapshots_to_gradle_cache_when_using_an_ivy_repository:
Since SNAPSHOTs are a Maven concept, they aren't treated as anything special in an 'ivy' repository. Unfortunately, there's not (yet) any way to specify a custom pattern for a 'maven' repository, so you're a bit stuck.
The best way to tell Gradle to check for updated versions of a dependency is to flag the dependency as 'changing'. Gradle will then check for updates every 24 hours, but this can be configured using the resolutionStrategy DSL.
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
dependencies {
compile group: "group", name: "projectA", version: "1.1-SNAPSHOT", changing: true
}
You can make Android Studio refresh its artifacts by using the command Invalidate Caches / Restart, which is in the File menu. I first used this command on Android Studio 3.2.1. It may exist on older versions too.
I use this after loading a new version of an external library (an AAR file) as a module, if classes or methods have been added or changed.

Categories

Resources