当前位置: 首页 > 工具软件 > ARouter > 使用案例 >

ARouter的坑之Program type already present: com.alibaba.android.arouter.routes.ARouter$$Group$$arouter

法风畔
2023-12-01

错误信息是这样子的,只有在编译运行的时候才跳出来

Program type already present: com.alibaba.android.arouter.routes.ARouter$$Group$$arouter
Message{kind=ERROR, text=Program type already present: com.alibaba.android.arouter.routes.ARouter$$Group$$arouter, sources=[Unknown source file], tool name=Optional.of(D8)}

原因是包名重复导致
看代码

@Route(path = "/arouter/test")
public class TestActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }
}

MainActivity

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ARouter.init(getApplication());
        findViewById(R.id.btn_tiao)
                .setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
            ARouter.getInstance().build("/arouter/test")
                    .navigation();
    }
}

找了半天把”/arouter/test” arouter不能用,人家源码中已经用了这个。

还有第二个坑
多个moudle的时候,除了library中,谁用了都要加这两个

        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [ moduleName : project.getName() ]
            }
        }
 annotationProcessor 'com.alibaba:arouter-compiler:1.1.4'
 类似资料: