<p dir="auto">I have this use case right now:</p>
<ul dir="auto">
<li>with flutter command -&gt; can't run app in debug cause of multidex</li>
<li>with Android studio -&gt; run without problem because for debug version it enable multidex by default</li>
</ul>
<p dir="auto">So I'm basically force to enable multidex just to be able to run the app in debug from a Flutter project. Flutter should be able to have the same behavior to avoid enabling multidex for nothing.</p>
<h2 dir="auto">Steps to Reproduce</h2>
<p dir="auto">Build app with more than 64K methods.</p>
<h2 dir="auto">Logs</h2>
<blockquote>
<p dir="auto">The number of method references in a .dex file cannot exceed 64K.<br>
Learn how to resolve this issue at <a href="https://developer.android.com/tools/building/multidex.html" rel="nofollow">https://developer.android.com/tools/building/multidex.html</a></p>
</blockquote>
<h2 dir="auto">Recommended Changes</h2>
<ol dir="auto">
<li>
<p dir="auto">Project template or <code class="notranslate">flutter.gradle</code> script should set the <code class="notranslate">multiDexEnabled</code> property to true, and add the <code class="notranslate">multiDexKeepFile file('multidex-flutter.txt')</code> config file. Example: <a href="https://github.com/flutter/flutter/files/2320127/multidex-flutter.txt">multidex-flutter.txt</a></p>
<div class="highlight highlight-text-adblock notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="io/flutter/app/FlutterApplication.class
io/flutter/view/FlutterMain.class
io/flutter/util/PathUtils.class"><pre class="notranslate">io/flutter/app/FlutterApplication.class
io/flutter/view/FlutterMain.class
io/flutter/util/PathUtils.class</pre></div>
</li>
<li>
<p dir="auto">Project template or <code class="notranslate">flutter.gradle</code> script should add the multidex dependency.<br>
<code class="notranslate">implementation 'com.android.support:multidex:1.0.3'</code></p>
</li>
<li>
<p dir="auto">FlutterApplication should have the following addition.</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@Override
protected void attachBaseContext(Context base)
{
    super.attachBaseContext(base);
    MultiDex.install(this);
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">Override</span>
<span class="pl-k">protected</span> <span class="pl-smi">void</span> <span class="pl-s1">attachBaseContext</span>(<span class="pl-smi">Context</span> <span class="pl-s1">base</span>)
{
    <span class="pl-en">super</span>.<span class="pl-en">attachBaseContext</span>(<span class="pl-s1">base</span>);
    <span class="pl-smi">MultiDex</span>.<span class="pl-en">install</span>(<span class="pl-smi">this</span>);
}</pre></div>
</li>
</ol>
<p dir="auto"><strong>Adding the <code class="notranslate">multiDexKeepFile</code> is important as the <code class="notranslate">FlutterApplication</code> class and its dependencies are required to me in the primary dex file or the Application class may its onCreate lifecycle event.</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Flutter 0.5.7 • channel v0.5.7 • https://github.com/slightfoot/flutter
Framework • revision 66091f9696 (7 weeks ago) • 2018-07-09 12:52:41 -0700
Engine • revision 6fe748490d
Tools • Dart 2.0.0-dev.63.0.flutter-4c9689c1d2"><pre class="notranslate"><code class="notranslate">Flutter 0.5.7 • channel v0.5.7 • https://github.com/slightfoot/flutter
Framework • revision 66091f9696 (7 weeks ago) • 2018-07-09 12:52:41 -0700
Engine • revision 6fe748490d
Tools • Dart 2.0.0-dev.63.0.flutter-4c9689c1d2
</code></pre></div>