Cannot access resources of dynamic feature module if AdMob is used

430 views
Skip to first unread message

alexander...@gmail.com

unread,
May 13, 2022, 3:02:26 AM5/13/22
to Google Mobile Ads SDK Developers
I had trouble accessing a resource located in my dynamic feature raw folder from my main activity. The installation of the dynamic feature worked fine and I could access it immediately with application context but I couldn't access it any more after I restarted my app.

splitInstallManager .startInstall(request);

... restart app ....

context.getApplicationContext().getResources().getIdentifier(filename, "raw", dynamic_feature_package_name);
-> returns null

AdMob initialization destroys the resource access if it is done too late. attachBaseContext is called before onCreate method of the activity so the solution was to do the AdMob initialization there:

@Override

protected void attachBaseContext(Context newBase) {

    super.attachBaseContext(newBase);
    MobileAds.initialize(this, ...
    SplitCompat.install(context);
}

So my issue is solved but you should either mention this solution in your docs or change your initialization so that MobileAds.initialize can be called in OnCreate method. You can read more details about this issue here: 


alexander...@gmail.com

unread,
May 14, 2022, 8:27:23 AM5/14/22
to Google Mobile Ads SDK Developers
Hi,
I have uploaded a sample app using your link.

My use case is pretty simple. I have an app with a lot of music files which are not needed by every user. So I want to move them to a dynamic feature module that they are downloaded on demand only. AdMob shall be used by the main activity. The dynamic feature consists only of resource files.

You will see that the resource access fails in the sample app after the app has been restarted with dynamic features installed. If you remove the AdMob Init lines or move them into attachBaseContext then it will work.

Alex
Message has been deleted

alexander...@gmail.com

unread,
May 16, 2022, 9:58:43 AM5/16/22
to Google Mobile Ads SDK Developers
Please note that putting MobileAds.initialize into attachBaseContext is not really an option for me. I have an alarm clock app which must also work in direct boot mode. AdMob initialization is not working in direct boot mode because it does not use the context.createDeviceProtectedStorageContext(). So if the device is in direct boot mode I need to do:

UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
if (um.isUserUnlocked())
    MobileAds.initialize(...)
else
    //try to initialize MobileAds later, but then dynamic feature access will not work !!!
   
If I try MobileAds.initialize in direct boot mode then the app even crashes! Maybe this is even a second issue you need to check. 

Mobile Ads SDK Forum Advisor

unread,
May 16, 2022, 10:07:11 AM5/16/22
to alexander...@gmail.com, google-adm...@googlegroups.com

Hi Alex,

Can you confirm if you already uploaded it to the link we provided previously? Upon checking, it is not yet available on the link. Can you provide it again to us?

If the file(s) you are looking to share are less than 25mb in total you can attach them to this case on your next reply. If you are having trouble attaching your file to this case or if your file(s) are larger than 25mb, you can share your files with me by performing the following steps:

1. Navigate to https://docs.google.com/forms/d/e/1FAIpQLSfkAiXMeYP-fw1W3Z-tT9uwmATEKO5X6S-th0gR2ezdKaaqfg/viewform?usp=pp_url&entry.400550049=Mobile+Ads+SDK&entry.460850823=5004Q00002asXlMQAU&entry.80707362=00107575
2. Fill out all fields, and attach your file(s).
3. Please reply back on this thread when you have uploaded your file(s). Please do not share this link.

Regards,

Google Logo
Princess Pamela
Mobile Ads SDK Team
 


ref:_00D1U1174p._5004Q2asXlM:ref
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages