简体   繁体   中英

Merging manifest of library is giving error in android project

I have simple application in which I want to use component of library project that I imported.

I merged the manifest of library and main project by adding manifestmerger.enabled=true in project.properties so that I can use components of library project into main project.

But when I tried to start activity of library project from main project with the code below:

    Intent intent = new Intent(MainActivity.this, ScanActivity.class);
    intent.putExtra("scanType", REGISTER_BARCODE);
    startActivity(intent);

I got the following errors

02-20 01:51:46.524: E/AndroidRuntime(23675): FATAL EXCEPTION: main
02-20 01:51:46.524: E/AndroidRuntime(23675): Process: com.example.smartdna_l1, PID: 23675
02-20 01:51:46.524: E/AndroidRuntime(23675): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.smartdna_l1/com.linksmart.smartdna6.ScanActivity}; have you declared this activity in your AndroidManifest.xml?

-

{com.example.smartdna_l1/com.linksmart.smartdna6.ScanActivity}

Where com.example.smartdna_l1 is main project package and com.linksmart.smartdna6.ScanActivity is library project path.

The path which got detected is wrong.

Now my question is that how to avoid merging of path so appropriate activity path can be detected correctly to start the activity.

Try this:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setComponent(new ComponentName("packagename//com.linksmart.smartdna6", 
                                     "classname//com.linksmart.smartdna6.ScanActivity"));
intent.putExtra("scanType", REGISTER_BARCODE);
startActivity(intent);

Make sure that in your library you've declared ScanActivity in library AndroidManifest.xml

For more info check Using an Android library project Activity within another project

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM