Skip to content

Commit

Permalink
solve the main dex file size is too large
Browse files Browse the repository at this point in the history
  • Loading branch information
luckybilly committed Dec 26, 2017
1 parent f7ec450 commit 20c6494
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ private static void loadRouterMap() {
// registerRouteRoot(new ARouter..Root..modulekotlin());
}

/**
* register by class name
* Sacrificing a bit of efficiency to solve
* the problem that the main dex file size is too large
* @author billy.qi <a href="mailto:[email protected]">Contact me.</a>
* @param className class name
*/
private static void register(String className) {
if (!TextUtils.isEmpty(className)) {
try {
Class<?> clazz = Class.forName(className);
Object obj = clazz.getConstructor().newInstance();
if (obj instanceof IRouteRoot) {
registerRouteRoot((IRouteRoot) obj);
} else if (obj instanceof IProviderGroup) {
registerProvider((IProviderGroup) obj);
} else if (obj instanceof IInterceptorGroup) {
registerInterceptor((IInterceptorGroup) obj);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

/**
* method for arouter-auto-register plugin to register Routers
* @param routeRoot IRouteRoot implementation class in the package: com.alibaba.android.arouter.core.routers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ class RegisterCodeGenerator {
//generate code before return
if ((opcode >= Opcodes.IRETURN && opcode <= Opcodes.RETURN)) {
extension.classList.each { name ->
//new a object for the specified class
mv.visitTypeInsn(Opcodes.NEW, name)
mv.visitInsn(Opcodes.DUP)
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, name, "<init>", "()V", false)
name = name.replaceAll("/", ".")
mv.visitLdcInsn(name)//类名
// generate invoke register method into LogisticsCenter.loadRouterMap()
mv.visitMethodInsn(Opcodes.INVOKESTATIC
, ScanSetting.GENERATE_TO_CLASS_NAME
, extension.registerMethodName
, "(L${extension.interfaceName};)V"
, ScanSetting.REGISTER_METHOD_NAME
, "(Ljava/lang/String;)V"
, false)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public class PluginLaunch implements Plugin<Project> {

//init arouter-auto-register settings
ArrayList<ScanSetting> list = new ArrayList<>(3)
list.add(new ScanSetting('IRouteRoot', 'registerRouteRoot'))
list.add(new ScanSetting('IInterceptorGroup', 'registerInterceptor'))
list.add(new ScanSetting('IProviderGroup', 'registerProvider'))
list.add(new ScanSetting('IRouteRoot'))
list.add(new ScanSetting('IInterceptorGroup'))
list.add(new ScanSetting('IProviderGroup'))
RegisterTransform.registerList = list
//register this plugin
android.registerTransform(transformImpl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ class ScanSetting {
* The package name of the interfaces
*/
private static final INTERFACE_PACKAGE_NAME = 'com/alibaba/android/arouter/facade/template/'

/**
* scan for classes which implements this interface
* register method name in class: {@link #GENERATE_TO_CLASS_NAME}
*/
String interfaceName = ''
static final String REGISTER_METHOD_NAME = 'register'
/**
* register method name in class: {@link #GENERATE_TO_CLASS_NAME}
* for {@link #interfaceName}
* scan for classes which implements this interface
*/
String registerMethodName = ''
String interfaceName = ''

/**
* jar file which contains class: {@link #GENERATE_TO_CLASS_NAME}
Expand All @@ -49,11 +49,9 @@ class ScanSetting {
/**
* constructor for arouter-auto-register settings
* @param interfaceName interface to scan
* @param registerMethod method to generate code into
*/
ScanSetting(String interfaceName, String registerMethod){
ScanSetting(String interfaceName){
this.interfaceName = INTERFACE_PACKAGE_NAME + interfaceName
this.registerMethodName = registerMethod
}

}

0 comments on commit 20c6494

Please sign in to comment.