New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Feature Activity test #5597
Comments
Switch to binary resources and try again. Add this to app/build.gradle inside the
|
When set Tested with AGP 4.2, Robolectric 4.6.1, Java 11, and targetSdkVersion is 29 or 30
|
Also, when set
|
Hi @ganadist , could you help to provide a sample app that can reproduce it? Thanks. |
Here is a sample app for test
|
After simple debug, I found that robolectric/resources/src/main/java/org/robolectric/res/android/LoadedArsc.java Lines 723 to 724 in 7697d12
|
Awesome, thanks for the example. Seems like this is an edge case in the ARSC unpacking logic. You can get the ARSC file by unzipping the ap_ file generated by the Gradle build. The file format is not well documented (I think it's mainly documented in the package manager source code), but it is relatively simple. I can look for more docs about the ARSC format. |
The robolectric/resources/src/main/java/org/robolectric/res/android/Chunk.java Lines 114 to 120 in 7697d12
The log says header size is 12, and it is less than Added log: if (child_chunk.data_size() / sizeof(ResTable_lib_entry) < dtohl(lib->count)) {
LOG(ERROR) << "RES_TABLE_LIBRARY_TYPE too small to hold entries.";
return {};
}
LOG(ERROR) << "header " << child_chunk.header_size();
loaded_package->dynamic_package_map_.reserve(dtohl(lib->count)); Printed log:
Look like Robolectric's |
I have modified if (header_size() > 0) {
ResTable_lib_entry lib_entry = new ResTable_lib_entry(device_chunk_.myBuf(), device_chunk_.myOffset() + header_size());
return lib_entry;
} And make sure entry_iter.myOffset() != entry_begin.myOffset() + dtohl(lib.count) * ResTable_lib_entry.SIZEOF Also need to add try-catch for new iterator entry (Actually it needs a checking for try {
entry_iter = new ResTable_lib_entry(entry_iter.myBuf(), entry_iter.myOffset() + ResTable_lib_entry.SIZEOF);
} catch (Exception e) {
System.err.println("failed to create new entry " + e.getMessage());
break;
} With above patches, the NPE disappears with
In a sense, the above modification is reasonable for me, so I will look at the new |
It seems But base apk is located on |
I tried to modify robolectric as #5597 (comment) , also modify to use package directory instead file. ganadist@85c7eb3#diff-16f874a8ce1fd6aa0c4faba55475bad44949ee2087391001f2a2d209a8dab559R47-R56 Also, I copied base.apk and split.apk, manually
Then, it seems PackageParser loaded apks properly, but I got another error while load resources. |
That's cool. I need more time to learn what AGP and frameworks do for dynamic feature apks. Update 1: a. AGP builds base apk and split apk. To sum up, AGP builds base apk and split apk with flavor and normal name, and install them together into Android device. The system will renames apks with I'm sorry to response too late, because it's too busy on work recently. Update 2: The error #5597 (comment) shows is caused by incorrect
The res dir is test apk, but this comment's res dir is its parent directory(Caused by: java.io.IOException: Failed to load asset path /home/ganadist/src/build/AndroidStudioProjects/vvv/dynamicfeature1/build/intermediates/apk_for_local_test/developDebugUnitTest). I will check the real res dir of app with dynamic feature on emulator. cc @ganadist. |
No folks take this issue at GSoC 2022, so I will take this issue again to continue related work at next few weekends. cc @ganadist .. |
Is there a solution to this problem? |
My team is not using dynamic modules, but wanted to comment we are experiencing a similar test failure with |
@utzcoz Hey thanks for your attention to this issue. I see that you have a PR with the fix. Do you have any timeline in mind by when we will be able to see this fix get released. |
@saran-epifi Sorry for pending/delaying. I think I will come back to this issue at next month after I resolved some pending PRs about Kotlin conversion for some modules' test code. |
Hi @utzcoz, any update about this issue? |
@clickrapha I am working on other stuffs recent years, and I think I still spend about some months on other stuffs. There is only one patch to fix some building errors, but it doesn't support full dynamic feature support now. And I need time to analyze the real dynamic feature supporting in AOSP and implement it in Robolectric. Also this task is listed in Robolecric GSoC 2024's project/idea list, and we can push the progress with students if someone wants to take this task. |
@utzcoz I am interested in working on this issue. |
Anyone who wants to take this project in GSoC 2024, please check and comment at #8865. |
Description
I've added new module to my Android project which is not a library:
apply plugin: 'com.android.library'
but a dynamic feature that I want to uninstall at some time from my App Bundle
apply plugin: 'com.android.dynamic-feature'
After work on UI done I wanted to write a Robolectric/AndroidX test to check my Activity behavior.
When I tried to run Activity with **launchActivity() ** I get
and when I tried with old:
Robolectric.setupActivity(AppOnboardingActivity::class.java)
I got
android.content.res.Resources$NotFoundException: Resource ID #0x7f08005f
Steps to Reproduce
Create Activity in the new Dynamic Feature module and just setup a test. My AndroidManifest.xml
...
Robolectric & Android Version
Robolectric 4.3.1
Link to a public git repo demonstrating the problem:
Project not public
The text was updated successfully, but these errors were encountered: