GithubHelp home page GithubHelp logo

componentbasedapp's Introduction

ComponentBasedApp

组件化App配置一览

  • 项目根目录gradle.properties配置: IsBuildModule=false

build.gradle文件配置

  • Library模块build.gradle配置:
buildTypes {
    debug {
        buildConfigField "String", "ENV", "\"debug\""
        signingConfig signingConfigs.debug
    }
    release {
        buildConfigField "String", "ENV", "\"release\""
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
//需要加上该参数否则会提示debug not found
publishNonDefault true 

sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.3.1'
    //router
    compile 'com.github.mzule.activityrouter:activityrouter:1.2.2'
}
  • 公共模块的build.gradle配置:
//资源文件名前缀约束
resourcePrefix "base_"

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //library依赖
    debugCompile project(path: ':Library', configuration: 'debug')
    releaseCompile project(path: ':Library', configuration: 'release')
    //router
    annotationProcessor 'com.github.mzule.activityrouter:compiler:1.1.7'
}
  • 业务模块的build.gradle配置:
if (IsBuildModule.toBoolean()) {
    apply plugin: 'com.android.application'
} else {
    apply plugin: 'com.android.library'
}
//配置AndroidManifest.xml路径
sourceSets {
	main {
		if (IsBuildModule.toBoolean()) {
			manifest.srcFile 'src/main/debug/AndroidManifest.xml'
	    } else {
			manifest.srcFile 'src/main/release/AndroidManifest.xml'
        }
    }
}
//资源文件名前缀约束
resourcePrefix "modulea_"

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':BaseModule')
    //router
    annotationProcessor 'com.github.mzule.activityrouter:compiler:1.1.7'
}

Module类创建

  • 分别创建各模块下的Module类:
//在app/src/main/java/{packageName}/目录下创建
@Module("app")
public class AppModule {
}

//在Library/src/main/java/{packageName}/目录下创建
@Module("library")
public class Library {
}

//在BaseModule/src/main/java/{packageName}/目录下创建
@Module("baseModule")
public class BaseModule {
}

//在ModuleA/src/main/java/{packageName}/目录下创建
@Module("moduleA")
public class ModuleA {
}
  • 创建Application类:
//把所有业务模块添加到依赖中
@Modules({"app", "moduleA"})
public class CommonApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
    }
}
  • 给使用到的Activity类添加别名(可传值),用于Routers寻址
@Router("AAA")
public class TestA extends AppCompatActivity {

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

@Router("AAA/:id/:title")
public class TestA extends AppCompatActivity {

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

主项目下AndroidManifest.xml配置

  • 配置RouterActivity,common为自定义标识
<activity
    android:name="com.github.mzule.activityrouter.router.RouterActivity"
    android:theme="@android:style/Theme.NoDisplay">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />

        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <data android:scheme="common" />
    </intent-filter>
</activity>
  • Router跳转
Routers.open(context, "common://AAA");
Routers.open(context, "common://AAA/13/这是标题");

componentbasedapp's People

Contributors

superwjl avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.