Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5431] Android: Enable Multi-Dex support for Android 4.X.X

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionDone
Resolution Date2018-01-03T22:02:57.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterMuhammad Ahmed Fahad
AssigneeShak Hossain
Created2017-12-08T08:18:43.000+0000
Updated2018-01-24T01:11:23.000+0000

Description

Currently we have multi-dex support and have made it default which enables us compiling apps with massive libraries and works fine for Android 5+. But when the number of method goes above 65K the app completely stops working on Android 4.X.X which the SDK still claims to support. Here is what is mentioned in the Android Studio doc to enable multi-dex for devices running Android versions which were prior to 5.0.0: *[https://developer.android.com/studio/build/multidex.html#mdex-pre-l](https://developer.android.com/studio/build/multidex.html#mdex-pre-l)* I tried changing the android application name, i.e.: * *as mentioned in: [https://developer.android.com/studio/build/multidex.html#mdex-pre-l](https://developer.android.com/studio/build/multidex.html#mdex-pre-l) but while trying to run the application, the app crashes with the error: E/AndroidRuntime(32659): java.lang.RuntimeException: Unable to start activity ComponentInfo {com.xyz/com.xyz.XYZActivity} : java.lang.ClassCastException: android.support.multidex.MultiDexApplication cannot be cast to org.appcelerator.titanium.TiApplication Or how can I override the attachBaseContext method on the Main application class?

Comments

  1. Muhammad Ahmed Fahad 2017-12-08

       
       package org.appcelerator.titanium;
       
       import android.content.Intent;
       import android.os.Bundle;
       import org.appcelerator.kroll.KrollDict;
       import org.appcelerator.titanium.proxy.ActivityProxy;
       import org.appcelerator.titanium.proxy.IntentProxy;
       import android.support.multidex.MultiDex;
       
       public class TiActivity extends TiBaseActivity
       {
       .
       .
       .
         @Override
         protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this);
         }
       .
       .
       .
       }
       
    ???
  2. Sharif AbuDarda 2017-12-08

    Hello, Can you share a sample app that we can test to verify the issue in Android 4.x.x and also see the response in 5.x.x and above. Please provide a sample app and list of steps to follow for successful regeneration. Thanks.
  3. Hans Knöchel 2017-12-09

    [~jquick] Thoughts?
  4. Joshua Quick 2017-12-11

    I've confirmed that multidex support for Android 4.x isn't reliable and will mostly likely crash on app startup. For now, the only reliable work-around is to set the min supported Android OS version to 5.0 by adding the following to your "tiapp.xml" file...
       <?xml version="1.0" encoding="UTF-8"?>
       <ti:app xmlns:ti="http://ti.appcelerator.org">
       	<android xmlns:android="http://schemas.android.com/apk/res/android">
       		<manifest>
       			<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="25"/>
       		</manifest>
       	</android>
       </ti:app>
       
    *Technical Reason:* The Titanium build tools needs to embed the "TiApplication" Java class and all of the Java classes it uses into the main dex file. This is because the application class needs to enable multidex support on Android 4.x, but the application class and its members need to be loaded successfully from the main dex file before doing so. This involves us passing a "--main-dex-list" command line argument when building a multidex app. This will never be a problem on Android 5.0 and above since those OS versions have built-in multidexing support.
  5. Joshua Quick 2018-01-24

    This issue will be resolved by the fix for [TIMOB-25597] in Titanium 7.0.2.
  6. Joshua Quick 2018-01-24

    Closing as duplicate.

JSON Source