🔥 Android component-based routing framework

Overview

README-CN

Latest version

module krouter-core krouter-compiler krouter-annotation krouter-plugin
version Download Download Download as plugin

Features

  • 支持通过路由获取intent
  • 支持方法注解,通过路由调用方法
  • 支持给fragment注解,通过路由获取fragment实例
  • 支持通过注解配置Activity跳转
  • 支持多模块项目
  • 支持增量编译,减小编译时间消耗

Quick Setup

Edit your project's build.gradle file and add classpath below.

buildscript {
    dependencies {
        classpath "io.github.jamgudev:krouter-plugin:1.0.5"
    }
}

And apply krouter-plugin on your application module.

plugins {
    id 'com.jamgu.krouter.plugin'
}

Multi-module support

If you project consists of multiple modules and you want to configure KRouter for one of them, apply krouter-plugin to your module will be enough.

Add code below to your module's build.gradle file.

plugins {
    id 'com.jamgu.krouter.plugin'
}

Krouter-plugin will automatically add dependencies for you. It will edit your Gradle file and add the following dependencies, which means you don't need to add them by yourself.

implementation "io.github.jamgudev:krouter-core:1.0.3"
kapt/annotationProcessor "io.github.jamgudev:krouter-compiler:1.0.3"

If you want to configure the dependence version on your own, add below code to your project's build.gradle.

ext {
	krouter_core_version = "1.0.5" // edit the version number you need
	krouter_compiler_version = "1.0.5"
	
	// flag whether to print compiler logs 
	krouter_compile_loggable = false
}

Get Started

Activity路由

@KRouter(MainPage.HOST_NAME)
public class MainActivity extends AppCompatActivity {

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

        findViewById(R.id.btn2Home).setOnClickListener(v ->
                KRouters.openForResult(MainActivity.this, new KRouterUriBuilder("helper")
                            .appendAuthority(HomePage.HOST_NAME)
                            .with(HomePage.USER_ID, "12345")
                            .with(HomePage.GAME_ID, "10001")
                            .with(HomePage.USER_NAME, "jamgu")
                            .build(), 10)
        );
    }

}

@KRouter(
    [HOST_NAME], longParams = [USER_ID, GAME_ID],
    stringParams = [USER_NAME]
)
class HomePageActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home_page)


        intent?.extras?.apply {
            tvGameId.text = getLong(GAME_ID, 0).toString()
            tvUserId.text = getLong(USER_ID, 0).toString()
            tvUserName.text = getString(USER_NAME, "")
        }

        btn2Main.setOnClickListener {
            KRouters.open(this, Schemes.MainPage.HOST_NAME)
        }

    }
}

class Schemes {
    object HomePage {
        const val HOST_NAME = "home_page"
        const val USER_ID = "USER_ID"
        const val USER_NAME = "USER_NAME"
        const val GAME_ID = "GAME_ID"
    }
    object MainPage {
        const val HOST_NAME = "main_page"
    }

}

Method路由

): Boolean { Log.d(TAG, "map in $TAG = $map") return true } } } val result = MethodRouters.invoke("showHomePageActivity", MethodMapBuilder() .with("aaa", "123456") .build()) ">
class HomePageActivity : AppCompatActivity() {

    companion object {
        private const val TAG = "HomePageActivity"

        @MethodRouter("showHomePageActivity")
        fun showHomePageActivity(map: Map<Any, Any>): Boolean {
            Log.d(TAG, "map in $TAG = $map")
            return true
        }
    }
    
}


val result = MethodRouters.invoke("showHomePageActivity", MethodMapBuilder()
                .with("aaa", "123456")
                .build())

全局路由拦截器

registerGlobalInterceptor(object : IRouterInterceptor {
    override fun intercept(uri: Uri, bundle: Bundle?): Boolean {
        // intercept if return true, invalid when isBlockGlobalMonitor was true
        return false
    }
})

单次路由监听

KRouters.open(context, "uri", null, object : IRouterMonitor {
    override fun beforeOpen(context: Context, uri: Uri): Boolean {
        // intercept if return true, return false by default.
        return super.beforeOpen(context, uri)
    }

    override fun afterOpen(context: Context, uri: Uri) {
        super.afterOpen(context, uri)
    }

    override fun onError(context: Context, msg: String, e: Throwable?) {
        super.onError(context, msg, e)
    }
})

Contact Me

Issues & Emails are welcome!

Email Address: [email protected]

License

Copyright (C) jamgu, KRouter Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
UltimateAndroid is a rapid development framework for developing your apps
UltimateAndroid is a rapid development framework for developing your apps

UltimateAndroid Version:0.10.2 UltimateAndroid is a rapid development framework for developing apps Master branch: Dev branch: V0.7.0 Ui Demo screensh

A framework for hook java methods.
A framework for hook java methods.

Legend Projects are out of date, plese move to: Whale Hook What is Legend? Legend is a Hook framework for Android Development, it allows you to Hook J

A modern framework for full stack web apps in Kotlin
A modern framework for full stack web apps in Kotlin

Kobweb is an opinionated Kotlin framework for creating websites and web apps, built on top of Web Compose and inspired by Next.js and Chakra UI.

A Mosby based VIPER library for Android

Moviper A Mosby based VIPER library for Android Why Moviper? You got tired because of fact that your Activities and Fragments were becoming god classe

Android part of the  Android Studio(IntellijIDEA) OkHttp Profiler plugin
Android part of the Android Studio(IntellijIDEA) OkHttp Profiler plugin

OkHttpProfiler Android Library Created by LocaleBro.com - Android Localization Platform The OkHttp Profiler plugin can show requests from the OkHttp l

Android common lib, include ImageCache, HttpCache, DropDownListView, DownloadManager, Utils and so on
Android common lib, include ImageCache, HttpCache, DropDownListView, DownloadManager, Utils and so on

android-common-lib 关于我,欢迎关注 微博:Trinea 主页:trinea.cn 邮箱:trinea.cn#gmail.com 微信:codek2 主要包括:缓存(图片缓存、预取缓存、网络缓存)、公共View(下拉及底部加载更多ListView、底部加载更多ScrollView、

A Model-View-Presenter / Model-View-Intent library for modern Android apps

Mosby A Model-View-Presenter and Model-View-Intent library for Android apps. Dependency dependencies { compile 'com.hannesdorfmann.mosby3:mvi:3.1.1

dexposed enable 'god' mode for single android application.

What is it? Dexposed is a powerful yet non-invasive runtime AOP (Aspect-oriented Programming) framework for Android app development, based on the work

A Job Queue specifically written for Android to easily schedule jobs (tasks) that run in the background, improving UX and application stability.

This Project is Deprecated! Thanks to everybody who've used Android Priority JobQueue. It was designed in a world where there was no JobScheduler, RxJ

Releases(v1.0.6)
Owner
Jiaming Gu
Jiaming Gu
kotlin-core - A full framework for making Android apps. Based on Anko and Kotson.

kotlin-core This package is not Android-specific, and can be used across platforms. However, for a good example of use in Android, take a look at kotl

Lightning Kite 36 Oct 3, 2022
LiteOrm is a fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line of code efficiently.

#LiteOrm:Android高性能数据库框架 A fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line

马天宇 1.5k Nov 19, 2022
Rosie is an Android framework to create applications following the principles of Clean Architecture.

Rosie The only way to make the deadline—the only way to go fast—is to keep the code as clean as possible at all times. — Robert C. Martin in Clean Cod

Karumi 1.8k Dec 28, 2022
A data-binding Presentation Model(MVVM) framework for the Android platform.

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED. As personal time contraints, I am currently unable to keep up. Please use official android da

RoboBinding open source 1.3k Dec 9, 2022
A full-featured framework that allows building android applications following the principles of Clean Architecture.

EasyMVP A powerful, and very simple MVP library with annotation processing and bytecode weaving. EasyMVP eliminates the boilerplate code for dealing w

null 1.3k Nov 19, 2022
Android Plugin Framework

Android Plugin Framework This project is pre-mature and may be changed very frequently. Introduction Android Plugin Framework (APF) aims to providing

Umeng Limited 322 Nov 17, 2022
MVVM framework for Android

RoboMVVM - MVVM Framework For Android RoboMVVM is an open source library that facilitates the use of the MVVM pattern in Android apps. The MVVM patter

Debdatta Basu 55 Nov 24, 2020
Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.

Codename One - Cross Platform Native Apps with Java or Kotlin Codename One is a mobile first cross platform environment for Java and Kotlin developers

Codename One 1.4k Dec 23, 2022
VasSonic is a lightweight and high-performance Hybrid framework developed by tencent VAS team, which is intended to speed up the first screen of websites working on Android and iOS platform.

VasSonic: A Lightweight And High-performance Hybrid Framework VasSonic is a lightweight and high-performance Hybrid framework developed by tencent VAS

Tencent 11.6k Dec 30, 2022
🔪 AOP development framework implemented through *Annotation + ASM + Gradle Transform API* for Android🤖

?? AOP development framework implemented through *Annotation + ASM + Gradle Transform API* for Android??

Pumpkin 325 Nov 22, 2022