android / android/codelab-android-dynamic-features
android.content.res.Resources$NotFoundException: Resource ID #0x0
- Dominant language
- Kotlin
- Stars
- 129
- Forks
- 51
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
Post installation of dynamic module, if we are accessing any resource through **Resources#getIdentifier(String name, String defType, String defPackage)** method which returns 0 as resourceId
We have added only one resource in our drawable folder i.e default_refer.png and made some changes in KotlinSampleActivity.
Kindly suggest what we are doing wrong.
```
class KotlinSampleActivity : BaseSplitActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_feature_kotlin)
// not working
try {
ContextCompat.getDrawable(this, resources.getIdentifier("default_refer", "drawable", packageName))
} catch (e: Exception) {
e.printStackTrace()
}
// working
try {
ContextCompat.getDrawable(this, R.drawable::class.java.getField("default_refer").getInt(null))
} catch (e: Exception) {
e.printStackTrace()
}
// working
try {
ContextCompat.getDrawable(this, R.drawable.default_refer)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
```
Contributor guide
Research direction
Start with KotlinSampleActivity and reproduce the failure after dynamic module installation, focusing on the Resources#getIdentifier call and the three drawable lookup forms shown. Trace how the dynamic module exposes default_refer.png and verify the resource lookup behavior; done means explaining the zero resource ID and providing a verified correction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100