自动组件化

在项目Build.gradle中添加依赖

plugins {
    id "calces.appconfig" version "3.3.0-alpha01"
}

appConfig {
    debugEnable false
    apps {
        app {
            applicationId "com.example.day02_02"
            mainActivity ".MainActivity"
            modules ':login',
                    ':success'
        }
    }

    modules {
        login {
            applicationId "com.example.login"
            mainActivity ".Login_MainActivity"

            isRunAlone true
        }

        success {
            applicationId "com.example.success"
            mainActivity ".Success_MainActivity"
            isRunAlone true
        }
    }
}

Application中添加

package com.example.day02_02;

import android.app.Application;

import com.alibaba.android.arouter.launcher.ARouter;

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ARouter.openLog();
        // 开启调试模式(如果在InstantRun(就是AndroidStudio2.0以后新增的一个可以减少很多编译时间的运行机制)模式下运行,必须开启调试模式!线上版本需要关闭,否则有安全风险)
        ARouter.openDebug();
        // 初始化尽可能早,推荐在Application中初始化
        ARouter.init(this);


    }
}

Activity中添加

package com.example.day02_02;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

@Route(path = "/aaa/MainActivity")
public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private Button bt_start;
    private Button bt_aaa;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        bt_start = (Button) findViewById(R.id.bt_start);

        bt_start.setOnClickListener(this);
        bt_aaa = (Button) findViewById(R.id.bt_aaa);
        bt_aaa.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_start:
                ARouter.getInstance()
                        .build("/login/Login_MainActivity")
                        .navigation();
                break;
            case R.id.bt_aaa:
                ARouter.getInstance()
                        .build("/success/Success_MainActivity")
                        .withString("name","哒哒哒")
                        .navigation();
                break;
        }
    }
}

你可能感兴趣的:(自动组件化)