Skip to content

Commit

Permalink
feat: 修复必须依赖Support包问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wzbos committed Jul 2, 2020
1 parent bbb2df4 commit 61a5c22
Show file tree
Hide file tree
Showing 55 changed files with 154 additions and 82 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Rudolph Android Router Framework(鲁道夫安卓路由框架组件)

- 支持组件API模块自动生成
- 自动生成路由Builder类与服务类的接口层;
- 加载更快,更稳定,无需dex扫描方式加载
- 加载更快,更稳定,无需插桩与dex扫描
- 无需指定模块名,接入更简单;
- 显式跳转与URL路由地址跳转融为一体,更方便快捷;
- 通过Builder方式传参,无需手动写参数名,从而减少参数传错和修改带来的Bug隐患;
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:appcompat-v7:${versions.supportLib}"
implementation project(':rudolph')
implementation project(':module-a')
implementation project(':module-b')
implementation project(':sampleA')
implementation project(':sampleB')

}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import android.support.v7.app.AppCompatActivity;

import cn.wzbos.android.rudolph.Rudolph;
import cn.wzbos.android.rudolph.example.module_a.MainActivityRouter;
import cn.wzbos.samplea.MainActivityRouter;

public class SplashActivity extends AppCompatActivity {

Expand Down
11 changes: 4 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ buildscript {
]

repositories {
jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
google()
jcenter()
}

dependencies {
Expand All @@ -27,13 +28,9 @@ buildscript {

allprojects {
repositories {
jcenter()
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
google()
}

configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
jcenter()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ siteUrl=https://github.com/wzbos/Android-Rudolph-Router
gitUrl=https://github.com/wzbos/Android-Rudolph-Router.git
licenseName=The Apache Software License, Version 2.0
licenseUrl=http://www.apache.org/licenses/LICENSE-2.0.txt
rudolph_version=1.0.3
rudolph_version=1.0.5
developerId=wzbos
developerName=zongbo.wu
developerEmail=sckoo@163.com
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Tue Sep 25 10:38:07 CST 2018
#Thu Jun 11 16:52:49 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 0 additions & 1 deletion module-a-api/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion module-b-api/src/main/AndroidManifest.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum RouteType {
METHOD,
FRAGMENT,
FRAGMENT_V4,
FRAGMENT_AndroidX,
SERVICE,
UNKNOWN,
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Created by wuzongbo on 2017/5/30.
*/
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.CLASS)
@Retention(RetentionPolicy.RUNTIME)
public @interface Arg {
String value() default "";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.wzbos.android.rudolph.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.TYPE})
public @interface Export {
/**
* export .class name
*/
String value() default "";

/**
* export singleton class
*/
boolean singleton() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
import java.lang.annotation.Target;

@Documented
@Retention(RetentionPolicy.CLASS)
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface Route {

String value() default "";

String tag() default "";

boolean export() default false;

boolean singleton() default false;

Class<?> clazz() default Object.class;
}
5 changes: 3 additions & 2 deletions rudolph-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ compileJava {
}

dependencies {
implementation 'com.squareup:javapoet:1.10.0'
implementation 'com.google.auto.service:auto-service:1.0-rc4'
implementation 'com.squareup:javapoet:1.11.1'
implementation 'com.google.auto.service:auto-service-annotations:1.0-rc7'
annotationProcessor 'com.google.auto.service:auto-service:1.0-rc7'
implementation 'org.apache.commons:commons-lang3:3.5'
implementation 'org.apache.commons:commons-collections4:4.1'
implementation project(':rudolph-annotations')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import cn.wzbos.android.rudolph.annotations.Arg;
import cn.wzbos.android.rudolph.annotations.Component;
import cn.wzbos.android.rudolph.annotations.Exclude;
import cn.wzbos.android.rudolph.annotations.Export;
import cn.wzbos.android.rudolph.annotations.Route;

import static cn.wzbos.android.rudolph.Consts.RAW_URI;
Expand Down Expand Up @@ -84,7 +85,8 @@ public class RudolphProcessor extends AbstractProcessor {
private TypeElement type_IBind;

private TypeMirror fragmentTm;
private TypeMirror fragmentTmV4;
private TypeElement fragmentTmV4 = null;
private TypeElement fragmentAndroidX = null;
private TypeMirror activityTm;
private TypeMirror serviceTm;
private TypeMirror parcelableTM;
Expand Down Expand Up @@ -112,7 +114,8 @@ public synchronized void init(ProcessingEnvironment processingEnvironment) {
serializableTM = this.elements.getTypeElement("java.io.Serializable").asType();
activityTm = elements.getTypeElement("android.app.Activity").asType();
fragmentTm = elements.getTypeElement("android.app.Fragment").asType();
fragmentTmV4 = elements.getTypeElement("android.support.v4.app.Fragment").asType();
fragmentTmV4 = elements.getTypeElement("android.support.v4.app.Fragment");
fragmentAndroidX = elements.getTypeElement(" androidx.fragment.app.Fragment");
serviceTm = elements.getTypeElement(Constant.ROUTE_SERVICE).asType();


Expand Down Expand Up @@ -152,6 +155,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
RouteType routetype;
for (Element element : routers) {
Route route = element.getAnnotation(Route.class);

ElementKind kind = element.getKind();
ClassName target;
if (kind == ElementKind.CLASS) {
Expand All @@ -164,9 +168,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
} else if (types.isSubtype(tm, fragmentTm)) {
// Fragment
routetype = RouteType.FRAGMENT;
} else if (types.isSubtype(tm, fragmentTmV4)) {
} else if (fragmentTmV4 != null && types.isSubtype(tm, fragmentTmV4.asType())) {
// Fragment V4
routetype = RouteType.FRAGMENT_V4;
} else if (fragmentAndroidX != null && types.isSubtype(tm, fragmentAndroidX.asType())) {
// Fragment AndroidX
routetype = RouteType.FRAGMENT_AndroidX;
} else if (types.isSubtype(tm, serviceTm)) {
routetype = RouteType.SERVICE;
} else {
Expand Down Expand Up @@ -303,22 +310,30 @@ private void generateRouteTable(MethodSpec.Builder builder, Element element, Cla
*/
private void generateRouterCls(TypeElement element, RouteType routeType, Route route) throws IllegalAccessException {
logger.warning("generateRouterCls:" + element.getSimpleName() + "Router");
Export export = element.getAnnotation(Export.class);

TypeName interfaceClsName = null;

TypeMirror mirror = APUtils.getTypeMirrorFromAnnotationValue(route::clazz);
if (mirror != null && ClassName.get(mirror) != TypeName.get(Object.class)) {
interfaceClsName = ClassName.get(mirror);
}

String clsName = element.getSimpleName() + "Router";
String clsName;
if (export == null || "".equals(export.value())) {
clsName = element.getSimpleName() + "Router";
} else {
clsName = export.value();
}

TypeSpec.Builder clsRouterBuilder = TypeSpec.classBuilder(clsName)
//增加注释
.addJavadoc(Constant.WARNING_TIPS)
.addModifiers(PUBLIC);

//生成单例
if (routeType == RouteType.SERVICE) {
if (route.singleton()) {
if (export != null && export.singleton()) {
clsRouterBuilder.addField(interfaceClsName, "instance", PRIVATE, VOLATILE, STATIC);
clsRouterBuilder.addMethod(MethodSpec.methodBuilder("get")
.returns(interfaceClsName)
Expand Down Expand Up @@ -360,10 +375,10 @@ private void generateRouterCls(TypeElement element, RouteType routeType, Route r
// logger.error("getExportApiPackageName:"+getExportApiPackageName(element));

try {
JavaFile file = JavaFile.builder(getExportApiPackageName(element, route.export()), clsRouterBuilder.build())
JavaFile file = JavaFile.builder(getExportApiPackageName(element, export != null), clsRouterBuilder.build())
.build();
File out_directory;
if (route.export() && (out_directory = getOutputDirectory()) != null) {
if (export != null && (out_directory = getOutputDirectory()) != null) {
// logger.info(out_directory.getAbsolutePath() + "/" + clsName+".java");
file.writeTo(out_directory);
} else {
Expand Down Expand Up @@ -425,7 +440,13 @@ private TypeSpec generate(TypeName interfaceClsName, ClassName builderType, Type
builder.superclass(ParameterizedTypeName.get(
ClassName.get(fragmentBuilderTm),
builderType,
TypeName.get(fragmentTmV4)));
TypeName.get(fragmentTmV4.asType())));
} else if (routeType == RouteType.FRAGMENT_AndroidX) {
// Fragment AndroidX
builder.superclass(ParameterizedTypeName.get(
ClassName.get(fragmentBuilderTm),
builderType,
TypeName.get(fragmentAndroidX.asType())));
} else if (routeType == RouteType.SERVICE) {
// Provider
builder.superclass(ParameterizedTypeName.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ private UriRouter(Builder builder) {
break;
case FRAGMENT:
case FRAGMENT_V4:
case FRAGMENT_AndroidX:
router = new FragmentRouter(builder);
break;
case SERVICE:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions sampleA-protocol/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="cn.wzbos.protocol.samplea" />
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cn.wzbos.android.rudolph.example.module_a_api;
package cn.wzbos.protocol.samplea;

import android.util.Base64;
import cn.wzbos.android.rudolph.example.module_a_api.bean.Broker;
import cn.wzbos.android.rudolph.example.module_a_api.bean.User;
import cn.wzbos.android.rudolph.router.ActivityRouter;
import cn.wzbos.protocol.samplea.bean.Broker;
import cn.wzbos.protocol.samplea.bean.User;
import com.google.gson.Gson;
import java.lang.CharSequence;
import java.lang.Character;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.wzbos.android.rudolph.example.module_a_api.bean;
package cn.wzbos.protocol.samplea.bean;

import android.os.Parcel;
import android.os.Parcelable;
Expand All @@ -20,6 +20,7 @@ protected Broker(Parcel in) {
age = in.readInt();
}


public static final Creator<Broker> CREATOR = new Creator<Broker>() {
@Override
public Broker createFromParcel(Parcel in) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.wzbos.android.rudolph.example.module_a_api.bean;
package cn.wzbos.protocol.samplea.bean;

import java.io.Serializable;

Expand Down
File renamed without changes.
12 changes: 7 additions & 5 deletions module-a/build.gradle → sampleA/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
Expand All @@ -13,8 +14,8 @@ android {
javaCompileOptions {
annotationProcessorOptions {
arguments = [
export_api_name : project.getName() + "-api",
export_api_package: "cn.wzbos.android.rudolph.example.module_a_api"
export_api_name : project.getName() + "-protocol",
export_api_package: "cn.wzbos.protocol.samplea"
]
includeCompileClasspath = true
}
Expand All @@ -38,12 +39,13 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "com.android.support:appcompat-v7:${versions.supportLib}"
implementation "com.google.code.gson:gson:${versions.gson}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
implementation project(':sampleA-protocol')
implementation project(':sampleB-protocol')

//rudolph
implementation project(':rudolph')
kapt project(':rudolph-compiler')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"
implementation project(':module-a-api')
implementation project(':module-b-api')

}
repositories {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.wzbos.android.rudolph.example.module_a">
package="cn.wzbos.samplea">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.wzbos.android.rudolph.example.module_a
package cn.wzbos.samplea

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cn.wzbos.android.rudolph.example.module_a;
package cn.wzbos.samplea;

import android.content.Intent;
import android.os.Bundle;
Expand All @@ -15,12 +15,12 @@
import cn.wzbos.android.rudolph.Rudolph;
import cn.wzbos.android.rudolph.annotations.Arg;
import cn.wzbos.android.rudolph.annotations.Route;
import cn.wzbos.android.rudolph.example.module_a_api.TestActivityRouter;
import cn.wzbos.android.rudolph.example.module_a_api.bean.Broker;
import cn.wzbos.android.rudolph.example.module_a_api.bean.User;
import cn.wzbos.android.rudolph.example.module_b_api.ITestService;
import cn.wzbos.android.rudolph.example.module_b_api.TestServiceRouter;
import cn.wzbos.android.rudolph.example.module_b_api.UserActivityRouter;
import cn.wzbos.protocol.samplea.TestActivityRouter;
import cn.wzbos.protocol.samplea.bean.Broker;
import cn.wzbos.protocol.samplea.bean.User;
import cn.wzbos.protocol.sampleb.ITestService;
import cn.wzbos.protocol.sampleb.TestServiceRouter;
import cn.wzbos.protocol.sampleb.UserActivityRouter;

import java.util.ArrayList;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -145,8 +145,6 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
TestServiceRouter.get().showMessage(MainActivity.this, "Hello Provider!");
// ITestService service = TestServiceRouter.builder().userId(1).userName("John").build().open();
// service.showMessage(MainActivity.this, "Hello Provider!");
}
});

Expand Down
Loading

0 comments on commit 61a5c22

Please sign in to comment.