fh_zhang
fh_zhang
  • 发布:2018-08-20 11:36
  • 更新:2020-07-22 01:28
  • 阅读:2460

扩展插件 如何获取application

分类:5+ SDK

混合开发 需要用到xutils,最好在application里初始化,但是怎么获取到application呢,

问题:继承DCloudApplication,application标签换成 android:name=".MyApp",报错:merger failed with multiple errors, see logs;
解决:在application标签下tools:replace="android:name",不再报错;
请教:这种会不会导致问题???????

问题:如果不继承DCloudApplication,继承StandardFeature写扩展插件的方式,在onStart里怎么获取到application呢??????????

官方能给个答案么,急求!跪谢!

2018-08-20 11:36 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

这种不会导致问题,这就是多个模块内同名(不同值)配置合并必然出现的,增加的“tools:replace”属性是对的。

屠龙

屠龙 -

兄弟,可以使用下面这段代码,用反射的方式获取DCloudApplication,可以进行x.Ext.init()的初始化喽
private static Application getApplicationInner() {
try {
Class<?> activityThread = Class.forName("android.app.ActivityThread");

        Method currentApplication = activityThread.getDeclaredMethod("currentApplication");  
        Method currentActivityThread = activityThread.getDeclaredMethod("currentActivityThread");  

        Object current = currentActivityThread.invoke((Object)null);  
        Object app = currentApplication.invoke(current);  

        return (Application)app;  
    } catch (Exception e) {  
        e.printStackTrace();  
        return null;  
    }  
}

该问题目前已经被锁定, 无法添加新回复