Error:Error converting bytecode to dex:
不同的模块使用了相同的分组,例如 AMoudle 定义了 @router(path=”/com/a”), BMoudle也定义了@router(path=”/com/b”) 就会出现这个问题,暴露服务出现这个问题同理。
使用拦截器实现登录校验
流程如下:
1,标记Activity需要登录(利用Arouter的extras参数,值为int类型)
@Route(path = RouterPath.IntentPath.AcgApp.Debug.HOBBIES_ACTIVITY, extras = ArouterConfig.NEED_LOGIN)
public class HobbiesActivity extends BaseActivity {
}
2,声明拦截器,如果跳转的是需要登录的Activity则判断是否已经登录
@Interceptor(priority = 999)
public class LoginInterceptor implements IInterceptor {
private Context mContext;
@Override
public void process(Postcard postcard, InterceptorCallback callback) {
//判断是否需要登录
if (postcard.getExtra() == ArouterConfig.NEED_LOGIN) {
boolean isLogin = xxx;
if (isLogin) {
callback.onContinue(postcard);
} else {
//跳转到登录,并且把需要跳转的url带给登录页,登录成功跳转该url
String originPath = postcard.getPath();
ARouter.getInstance().build(RouterPath.IntentPath.AcgApp.Debug.PHONE_LOGIN_ACTIVITY)
.withString(ArouterConfig.AROUTER_LOGIN_SKIP_PATH, originPath)
.navigation(mContext);
}
} else {
callback.onContinue(postcard);
}
}
@Override
public void init(Context context) {
mContext = context;
}
}