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.
Related
For a library I'm using, I get an error on some of the overridden methods:
Inheritance from an interface with '#JvmDefault' members is only allowed with -Xjvm-default option
The answer prior to my Bumblebee upgrade was to use kotlinOptions in the app build.gradle:
android {
kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=compatibility']
jvmTarget = "1.8"
}
but now, kotlinOptions always breaks the build:
No signature of method: build_5rl9tbmrzydf364yqkdyvcpyq.android() is applicable for argument types: (build_5rl9tbmrzydf364yqkdyvcpyq$_run_closure1) values: [build_5rl9tbmrzydf364yqkdyvcpyq$_run_closure1#60f02a40]
so where else can I set the compiler options for Kotlin in Android Studio Bumblebee?
Or, how can I fix the build so that kotlinOptions works again?
The trick is to slow down and double check that you have all the requirements in your Gradle file for an Android Kotlin application. If you're missing version, or missing declaring dependencies, you're sure to get build errors. Once I checked off the boxes in the link here, everything built as it was supposed to.
In my case, I'm an iOS developer so a lot of 'fear of the unknown' was at work against me here. Once I just settled down and paid attention to giving my Gradle build the specifications it needed, I got more familiar and comfortable with the build system, and got the results I expected.
https://developer.android.com/kotlin/add-kotlin
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 have created a Gradle task that generates a javadoc using Doclava:
My code (the arguments of some of my methods) references classes defined in Android. When Javadoc is built, these references link correctly to the Android online reference. However, when I use the #ling tag to link to Android references, it does not work and I get something like:
configurations {
jaxDoclet
classpaths
}
dependencies {
// For Doclava JavaDoc
jaxDoclet("com.google.doclava:doclava:1.0.6")
classpaths files('build/intermediates/classes/debug')
classpaths project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.allJava
source += fileTree("build/generated/source/r/debug")
title = null
options {
docletpath = configurations.jaxDoclet.files.asType(List)
doclet "com.google.doclava.Doclava"
bootClasspath new File(System.getenv('JAVA_HOME') + "/jre/lib/rt.jar")
classpath += configurations.classpaths.files.asType(List)
addStringOption "public"
addStringOption "federate android", "http://d.android.com/reference"
addStringOption "federationxml android", "http://doclava.googlecode.com/svn/static/api/android-10.xml"
}
}
warning 101: Unresolved link/see tag "Runnable" in com....
In similar questions in SO, it was advised to use -link and -linkoffline flags. However, when I do that I get:
javadoc: error - invalid flag: -linkoffline
I am using Android Studio 1.5.1 and Gradle 2.11.
Update
It seems that Doclava may not support -link and -linksoffline according to these tickets. If I use the default doclet, links work correctly.
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.
I am trying to make a shim in VS 2012 ultimate as it described in MSDN site:
[TestClass]
public class TestClass1
{
[TestMethod]
public void TestCurrentYear()
{
int fixedYear = 2000;
using (ShimsContext.Create())
{
// Arrange:
// Detour DateTime.Now to return a fixed date:
System.Fakes.ShimDateTime.NowGet =
() =>
{ return new DateTime(fixedYear, 1, 1); };
// Instantiate the component under test:
var componentUnderTest = new MyComponent();
// Act:
int year = componentUnderTest.GetTheCurrentYear();
// Assert:
// This will always be true if the component is working:
Assert.AreEqual(fixedYear, year);
}
}
}
see http://msdn.microsoft.com/en-us/library/hh549176.aspx
But when I compile my test project I get a notion in Output:
warning : Some fakes could not be generated. For complete details, set Diagnostic attribute of the Fakes element in this file to 'true' and rebuild the project.
How can I resolve this warning?
Visual Studio 2012 Update 1 improved code generation in Fakes to simplify troubleshooting of code generation problems. Whenever a Stub or a Shim could not be generated for a particular type, Fakes can now generate a warning message - you can see this in the Error List window of Visual Studio.
However, to prevent the number of warnings from becoming overwhelming for a large assembly, such as System, Fakes generates a single warning by default. You can see a complete list of warning messages by setting the Diagnostic attribute of the Fakes XML element in the .Fakes file to "true" or "1" and rebuilding the project. (See the first line of code below for an example.)
To resolve the warning, change the .Fakes file to generate only those Stubs and Shims you need in your tests. Details here
here a complete list of available options
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
<Assembly Name="System" Version="4.0.0.0"/>
<StubGeneration Disable="true" />
<ShimGeneration>
<Clear/>
<Add FullName="System.DateTime!"/>
</ShimGeneration>
</Fakes>
I have resolved it already alone.
It was .Net Framework 4.0 in Property.
Changing on 4.5 resolve the problem.
Try removing those .Fakes file.
I removed them accidentally and compiled, and the warnings are gone.
I am not sure what the impact is, but everything seems to run fine. I think it causes the compile to recompile the fakes file everything there is a build.