Flutter Build Failed due to Mutlidex Error - android-multidex

This is the Error which i recieved when i tried to Run the Flutter Application.
Cannot fit requested classes in a single dex file. Try supplying a main-dex
list.# methods: 67061 > 65536.
The number of method references in a .dex file cannot exceed 64k.
Then i Updated build.gradle as "multiDexEnabled true ". But then i
recieved different Error.
Could not find method multiDexEnabled() for arguments [true] on object of type com.android.build.gradle.AppExtension.

You missed the dependency in order to enable multidex.
Open project/app/build.gradle and add:
dependencies {
...
implementation 'com.android.support:multidex:1.0.3'
}

Related

Disable warning lint for a method in external library in Android Studio

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.

How do I limit platforms that I build for?

I've tried doing abiFilters ["armeabi-v7a"] instead of abiFilters.add("armeabi-v7a") but that results in linking error and message:
Execution failed for task ':linkMyModuleArm64-v8aDebugSharedLibrary'
Basing on this message I suspect that project is still build for all platforms...
Inside your model block create android.productFlavors block (you should already have this). Then apply your abiFilter like this:
create("arm"){
dimension = "abi"
ndk.abiFilters.addAll(['armeabi'])
}
Adding abiFilters.addAll(['armeabi']) to your main ndk block, would set the default for all "Variants"
Have a look at http://tools.android.com/tech-docs/new-build-system/gradle-experimental#TOC-Other-Build-Options

Android Studio Messages window

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.

Xamarin Linker : Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector

With a skeleton project with FirstView from HotTuna package, and with Build linker behavior set to "Link all assemblies", I get the following error:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
Using NuGet package v3.1.1 for all MvvmCross (4 packages)
LinkerPleaseInclude file does have the line
[MonoTouch.Foundation.Preserve(AllMembers = true)]
Using the latest stable build:
On PC:
Xamarin for VS 1.12.278
Xamarin.iOS 1.12.278
Mac:
Xamarin.iOS 7.2.2.2
Of course with Linker behavior of SDK only, it runs fine. Any suggestions anyone?
Solved; So, with the basic project, there were three consecutive errors in the following order:
System.MissingMethodException: Default constructor not found for type Cirrious.CrossCore.IoC.MvxPropertyInjector
can be resolved either by --linkskip=Cirrious.Core (ugly), or by including the following in LinkerPleaseInclude.cs
public void Include(MvxPropertyInjector injector){
injector = new MvxPropertyInjector ();
}
Next error is:
Cirrious.CrossCore.Exceptions.MvxException: Failed to construct and initialize ViewModel for type {0} from locator MvxDefaultViewModelLocator - check MvxTrace for more information
This one is difficult; Simple fix is to ofcourse to do a --linkskip=portableLibrary, or to crate an instance of the ViewModel somewhere (perhaps in LinkerPleaseInclude.cs); problem with the second approach at-least in my case is, most of my VM doesn't have a parameter less constructor, and obviously using IOC in this case wouldn't help.
Final Error:
System.ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
Either use --linkskip=System (ugly), or add the following to LinkerPleaseInclude.cs
public void Include(INotifyPropertyChanged changed)
{
changed.PropertyChanged += (sender, e) => {
var test = e.PropertyName;
};
}
This was enough for my basic project to run with LinkAllAssemblies, Using LLVM optimizer, and Use SGen collector.
Hope this will help anyone looking for a solution.
I hit this when my XCode was out of sync with the latest Xamarin on my Mac. Upgrading XCode to the latest resolved the problem.

Duplicate identifier 'nodeName' in jquery.d.ts

I have referenced jquery.d.ts in my TypeScript Project in Visual Studio 2012 and am getting the following error:
Error 1 Duplicate identifier
'nodeName' C:\DEV\MyProject\Scripts\JQuery\jquery.d.ts 786 2 pageMain.ts
Which leads to the following code in jquery.d.ts:
interface EventTarget {
nodeName: string;
}
I have restarted VS2012, and then again after deleting all the .sou files for the project.
I have checked all my references (includes) and found no other reference to EventTarget.
I have looked in lib.d.ts, and indeed, there is a EventTarget interface, but it does not implement nodeName.
FYI: I found two copies of lib.d.ts on my machine, and checked them both: does anyone know which one is used by the compiler? I did mods on both (changing the window.alert to window.alert2), but they had no effect.
Your jQuery.d.ts needs to be updated.
Here is a quick way to test the issue:
declare var x: EventTarget;
x.nodeName = '';
If you run this on the TypeScript Playground, you'll see that nodeName does not exist on EventTarget. Indeed, if you look at the lib.d.ts file, you'll find this:
interface EventTarget {
removeEventListener(type: string, listener: EventListener, useCapture?: bool): void;
addEventListener(type: string, listener: EventListener, useCapture?: bool): void;
dispatchEvent(evt: Event): bool;
}
However, if you run the same code within Visual Studio with Web Essentials, you'll find that nodeName does exist on EventTarget. This is because Web Essentials is using a newer version of lib.d.ts - if you disable Web Essentials, you would get the same error as you see in the Playground.
These issues will happen occasionally as the standard definitions are improved to keep up with what browsers actually support. Your definition files should be adjusted to keep in line with your development tools, with a preference to changing files such as jquery.d.ts rather than lib.d.ts.
Interesting bug, I faced same issue with className instead of nodeName
After spending sometime trying to solve the issue I found this article link in jquery.d.ts file
I am maintaining general.d.ts file to create required interface items needed.
I added the following definition to the file
interface EventTarget {
className: string;
}
Immediately I got an error message of duplicate identifier.
I kept it and saved general.d.ts, and went back to my original working file, I found the compiler passed through.
My assumption it is Web Essentials bug failing to load definitions properly.

Resources