In an Android Studio project I have the following lines:
// do variant level customisation
android.applicationVariants.all { variant ->
// adjust applicationId for Free variants
if (variant.name.contains("Free")) {
variant.mergedFlavor.applicationId += "_free"
}
}
This generates the following deprecation warning:
'MergedFlavor.getApplicationId()' is obsolete and has been replaced with 'VariantProperties.getApplicationId()'.
I have been unable to find an alternative syntax that will replace what I have and remove the deprecation warning. I am aware of "applicationIdSuffix" but this will always add a leading "." which I cannot have. Any thoughts much appreciated.
I work in the Android 4.1.2 studio. I updated Gradle plugin
- classpath 'com.android.tools.build:gradle:3.5.3'
+ classpath 'com.android.tools.build:gradle:4.1.2'
and
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
After that, I tried to build the apk, but the build failed due to errors in kotlin class, for example: "'handleMessage' overrides nothing " for Handler class, and "Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type" for intent.getParcelableExtra. The Android studio itself does not show me such errors in kotlin class. Can you tell me what this is related to and how I can enable the display of errors in android studio
I have tried rebuild, clean , invalidate & restart.
Click the "Handler" to open the Decompiled Handler.class, search "handleMessage" in it, the new definition looks as below:
public void handleMessage(#NonNull Message msg) {
throw new RuntimeException("Stub!");
}
So the argument msg has been changed to #NonNull.
Therefore, to fix this issue, the original override statement
override fun handleMessage(message: Message?)
should be updated to remove the ? to match the function definition.
override fun handleMessage(message: Message)
In my Android project I have an external library with following method:
// Some external library
class Foo {
#CheckReturnValue
public final Bar returnBar(Bar bar) {
...
}
}
I have to call this method a lot in my project, but I do not need the returned value of this method. All I need is the side effect of the method. So this is how I use it:
fooInstance.returnBar(barInstance) // ignore returned value
The problem with the above code is that Android Studio editor will show CheckResult warning lint. What I can do is to either just live with that warning lint or disable CheckResult for the entire project or module, but I was wondering if there is a better approach to this warning.
What I cannot do is to put SuppressLint because I will be using that method 100 < times in my project and adding SuppressLint to every single usage is not really feasible.
I already went through Android Studio inspection settings but unfortunately was not able to find anything that can help. I would be grateful if you could provide literally any thought on this problem.
I select the following code:
//This is for debugging Live Template
try {
} catch (Exception ex) {
}
then click Tools > Save as Live Template...
Nothing happens. Could anyone offer a tip on how to select a snippet and save as a live template?
https://youtrack.jetbrains.com/issue/IDEA-174644 -- this looks like your case.
It's fixed for 172/173.xxx branches -- no idea what Android Studio version it would be.
Workaround for now -- make selection with no leading whitespace .. and edit created Live Template after if required.
How can I configure Android Studio/IntelliJ Idea to show more than 101 error messages when compiling?
I know there are more than 101 errors, but I am using Android Annotations and I get a lot of import errors when something is wrong. Those import errors fill up the messages window and I can't see the actual errors that need to be fixed.
Thanks!
This 101 error limit is imposed by the underlying compiler , not the IDE. So to increase it, you have to change the default compiler settings.
Go To : Preferences -> Build, Execution, Deployment -> Compiler.
There, you'll find an option of passing additional command line options to the compiler. There you can change the max errors limit.
The compiler used by Android studio is javac and it offers the following options :
-Xmaxerrs number : Set the maximum number of errors to print.
-Xmaxwarns number : Set the maximum number of warnings to print. `
So, you can pass :
-Xmaxerrs 400 -Xmaxwarns 1000 to make the maximum errors reported to 400 and maximum warnings reported to 1000.
That's one way to do it in IDE UI and change it globally for all projects.
You can also set this for a specific project by passing these command line options to the compiler through the gradle file of the project. Here's the syntax for that:
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "400" << " -Xmaxwarns" << "1000"
}
In Gradle, change the allprojects of your Project build.gradle as following:
allprojects {
repositories {
jcenter()
}
// Allow 400 errors.
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xmaxerrs" << "400"
}
}
}
As everybody pointed out, maximum errors displayed is a Compiler rather than an Android Studio setting. I am using kotlin annotation processor kapt for incremental compilation of databinding, room and dagger. The following addition to build.gradle solved the problem:
kapt {
javacOptions {
// Increase the max count of errors from annotation processors.
option("-Xmaxerrs", 500)
}
}
Hope it helps someone, when applying the various other options suggested I kept seeing 50 errors.
I don't know, how to force Messages window show more than 101 errors, but maybe this would help.
At the end of Messages window you can see:
Or you can call console from icon:
Here how it looks:
I believe you can find all information there.
Also there is a possibility to export log to text file, this also might help you.
Thanks.
Add the Android Annotations Support JAR to your build.gradle -
compile 'com.android.support:support-annotations:23.3.0'
This should get rid of the import errors.