DexPatcher / dexpatcher-gradle

Modify Android applications at source-level in Android Studio
https://dexpatcher.github.io/
GNU General Public License v3.0
83 stars 17 forks source link

[QUESTION] Accessing R.id.x in separate APK #38

Closed auermich93 closed 2 years ago

auermich93 commented 2 years ago

Hi @Lanchon,

we are trying to pack generated system tests (e.g. espresso tests) obtained from our test generator into a separate APK. This is similar to the APK you obtain when running ./gradlew assembleAndroidDebugTest. Assuming you have access to the source code, this is pretty easy, you simply copy the obtained tests into the androidTest folder and run the gradle task. But, in our case we assume no access to the source code, just to the APK. We thought about copying the tests into some kind of template repository that is minimal. Then, we need to adjust the package name such that it matches the AUT. Finally, we would like to run ./gradlew assembleAndroidDebugTest to build the APK and sign it afterwards. However, we would like to use within those tests the ids of the auto-generated R class, e.g. R.id.my_button. I know that we could look up the real ids within the APK of the AUT and replace R.id.my_button with 0xCAFE for instance. But is there any other option rather than using the raw ids or doing everything at the smali representation level?

Any help is appreciated. Thanks in advance!

Lanchon commented 2 years ago

hi. i don't really understand what you are trying to do. how are you using dexpatcher-tool or dexpatcher-gradle now and what is it not doing correctly? can you provide logs?

auermich93 commented 2 years ago

This is not related to dexpatcher-tool or dexpatcher-gradle at all, but you already solved the problems we actually face. And I didn't find another way to contact you. Sorry for the inconvenience! @Lanchon: To re-phrase the problem: I want to pack a couple of espresso tests or any other tests in the form of java classes into a separate APK since this is the common way. Apart from the dependencies I need to declare, I would like to access within those tests a ui element via R.id.some_id, but therefore we need access to the auto-generated R class. I guess you basically solved this problem already within the dexpatcher implementation? I thought about using some sort of template repository defining the necessary dependencies within the build.gradle file. Then, one copies over the tests and runs the gradle task assembleAndroidDebugTest to produce the APK. But, as previously mentioned, I need to provide the auto-generated R class, where the ids match with the ids of the AUT. I saw you are using some R.id.hack class or whatever.

auermich93 commented 2 years ago

Using reflection seems to be the easiest solution.