Gradle: List deprecated features - java

I am getting a warning about the usage of deprecated features in my build.
Is there a way to list all the deprecated features so that I may go through and update my code?
*clarification
I know I can go to the Gradle documentation and see what is now deprecated, what I would specifically like is a way to go through MY code and list MY deprecated features.

I just faced the exact same problem and running the Gradle build task every time through the command line wasn't the best option for me because, during development, I usually just use the built-in Gradle build task run, so:
I know I can go to the Gradle documentation and see what is now deprecated, what I would specifically like is a way to go through MY code and list out MY deprecated features.
You can do this by adding the mentioned --warning-mode=all flag to your gradle command line options in your Android Studio settings:
This will print the proper warnings for you to be aware of what are the specific deprecated features your app is using.
Also, I know you asked this near a year ago, but, it might be useful for other people facing the same issue.

In order to change the warning verbosity level in the Android Studio IDE, you can add the option org.gradle.warning.mode=(all,none,summary) to the gradle.properties file, which can be found in the root directory of your project.
Add following line to set the warning mode to all:
...
org.gradle.warning.mode=all
...

Use Gradle option -Dorg.gradle.warning.mode=(all,none,summary) to control verbosity, for example, mode all will log all warnings with detailed descriptions:
./gradlew build -Dorg.gradle.warning.mode=all
More details can be found in the official documentation: Showing or hiding warnings

Go to the build.Gradle (Module) file.
replace Compile with implementation.
Sync the gradle file and you will not receive the warning again.

Related

Get javac to use androidx

I am now coding Android apps without using Android Studio, and when I compile, I encountered the errors:
./src/com/example/projectname/GamePanel.java:8: error: cannot find symbol
import androidx.annotation.NonNull;
where the "^" points at the period before "NonNull", and
error: package androidx.appcompat.app does not exist
And my compile command is:
javac -d obj -sourcepath src -classpath ../android/platforms/android-32/android.jar ./src/com/example/projectname/*.java
The internet tells me that I should set android.useAndroidX to true, but I am not using Android Studio. Is there any way to let javac know that I am using AndroidX?
OK, so the problem is that the NonNull annotation is not defined in that JAR file. (Or at least, not in the android.jar that I found ... on Github.)
I managed to find a JAR containing androidx.annotation.NonNull in the Maven Central Repository: https://mvnrepository.com/artifact/androidx.annotation/annotation/1.3.0
But I suspect that you are going to find more of these issues as your project gets more complicated.
Is there any way to let javac know that I am using AndroidX?
No there isn't. The javac compiler understands nothing about Android let alone AndroidX. It only knows about what you added to the compile-time classpath. So if you are going to persist with compiling using javac directly, you are going to have to figure out how to find the JARs that you need for yourself1.
My recommendation would be:
Just use Android Studio. It really isn't that slow ... when you take into account all of the features it provides to make coding, testing, debugging, etc.
You can also use the Gradle build tool2 independently of Android Studio. It has a plugin designed especially for building Android apps; see https://developer.android.com/studio/build. Among other things, it will automate the downloading of the dependencies and the configuration of the classpath.
1 - And down the track you will need to manually update the JARs that you manually downloaded, etc.
2 - There are alternatives such as Maven, Ant and so on, but AFAIK Gradle has the best integration for Android.
Is there any way to let javac know that I am using AndroidX?
Yes, you can download the JAR files for the libraries you are using and add them to the classpath.
However, this leads down a path of suffering and sadness because you will have to download many different JAR files that are implement different parts the androidx package, depending on what features you need.
I strongly suggest you to use Android Studio. It is an incredible tool that makes Android development easier than it otherwise would be.
If your goal here is to compile your app from the command line, then you need to learn about gradle. This is a tool that will download the dependencies for you then run javac with the correct classpath set. Basically it automates all the steps you would need to take to do this manually.

troubleshooting debug problems in flutter

I experienced a problem in this section Could not determine the dependencies of task': app: compileProfileJavaWithJavac
I have searched various sources but have not found a solution, and I use the flutter framework.
I have tried various ways such as searching for references related to my problem, but I did not find a solution, either on github, stackoverflow and also flutter.
Could not determine the dependencies of task ':app:compileProfileJavaWithJavac'.
Could not resolve all task dependencies for configuration ':app:profileCompileClasspath'.
Could not find androidx.legacy:legacy-support-v4:28.0.3.
You have to migrate to AndroidX.
Go to your android/gradle.properties and add this line of code:
android.useAndroidX=true
This will make sure to use the AndroidX library instead of the Support library.
EDIT:
You may also want to add android.enableJetifier=true which enables you the Jetifier, i.e: a set/collection of libraries to make developer's life easier. For more info. look here.

IntelliJ IDEA code reformat not working

I am using IntelliJ IDEA version 2017.3, then I install plug-in CheckStyle-IDEA v 5.16.0 successful, I install Apache Maven Checkstyle Plugin to run myCheckFile.xml. At install phase, I received many check style error like:
Indentation: '.' has incorrect indentation level 6, expected level should be 8.
Indentation: 'new' has incorrect indentation level 6, expected level should be 8.
After importing CheckStyle settings, I expect when I hit Ctrl+Alt+L inside IntelliJ IDEA all check style error will die but that doesn't happen, is there's something i'm missing ?
You might have a .editorconfig file which is taking precedence. I ran into the same problem and my solution was to comment out the .editorconfig file. Our team is using JHipster, which automatically generates a .editorconfig file. This generally has just a few key settings, including indent_size=4. I was experimenting with Google's checkstyle xml settings and saw the same overall issue you were seeing, where the checkstyle plugin was indicating the indentation was wrong, but the code/reformat option wasn't fixing it.
TL;DR - see if you have a .editorconfig file and if so delete it or comment out the conflicting styles.

Using codenameone with lombok in Eclipse

I wonder if anyone is using codenameone with lombok in Eclipse. I've googled, but all I could find is an old question of mine.
A tiny success
I've tried it, took a demo project, modified nothing and opened it in my Eclipse configured for Lombok. When compiling, I got the same stacktrace as here. I've added
/usr/lib/jvm/java-8-oracle/lib/tools.jar
to the path under Preferences -> Installed JREs -> Edit -> JRE system libraries (which may be a pure non-sense) and it didn't help.
Then I've replaced compiler="modern" by compiler="extJavac" in build.xml and it compiles. I can even use Lombok annotations and they compile and work in the simulator.
The problem
I'm afraid, this was the simple part. I guess, for submitting, I need to replace the source code by the output of delombok. I've tried to submit it as is and nothing happened (no error, no response).
Has anyone done it already?
Any tips?
You shouldn't change the classpath but if the bytecode has access to the properties then it should "just work". If you look at the build.xml file you will notice that it has targets for every one of the supported platforms and before the target occurs you will see a compilation target that packages the JAR that's sent to the servers.
Steve wrote a post about porting other languages to Codename One. This is simple by comparison.
It actually works! All I had to do was to
add the path to lombok.jar to the Java Build Path1
in the javac call of the jar task
replace compiler="modern" by compiler="extJavac"
add the path to lombok.jar to the classpath
1 This is not recommended as the dependency is unavailable on the build server, but that's exactly right. Lombok is a compile-time only dependency and the build seems to be based on the dist.jar, where Lombok has already done its job.
One year later: There was a problem with my old setup, so I installed everything anew and it seems to work. Just note that there are three javac tasks in the build.xml.

Android Lint Check for specific project

I am using Android Studio for running custom lint check. I have created Custom Lint Library and after the build I am copying customlint.jar by
cp linte/build/libs/customlint.jar ~/.android/lint/
This will copy the customlint.jar to ~/.android/lint/ folder.
Now when I run lint its working as expected.
But when I open other sample projects the custom lint errors are appearing. How to avoid this?
Is there anyway so that customlint.jar is not copied ~/.android/lint/ folder and apply the custom lint checks only to my projects.
I have logged the same issue here
https://code.google.com/p/android/issues/detail?id=233632
As per the reply this feature will be included in future sprints.
Note - Will edit this answer once it is included. Hence marking this as answer.

Categories

Resources