问题
I am getting images id from drawable-hdpi at run time using getIdentifier method using following code
mContext.getResources().getIdentifier(mContext.getPackageName() + ":drawable/" + mCur.getString(mCur.getColumnIndex(Constant.COLUMN_IMAGE_DRAWABLE)), null, null)
i also tried following ways
mContext.getResources().getIdentifier(mCur.getString(mCur.getColumnIndex(Constant.COLUMN_IMAGE_DRAWABLE))+"", "drawable", mContext.getPackageName());
and set image resource using following code
imgPosotion.setImageResource(item.getDrawable());
both work when i turn on instant run from android studio but unfortunately none of them work when i am turn off instant run feature from android studio. I am using Proguard at debug as well as release time using following code
release {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
Observed scenario Image are not showing. Code run perfect and showing images when run with instant run. i make release build and then decompile it, i observed that images(.png extension) are there in res/drawable-hdpi folder but sizes are converted into 1*1 dimension(67byte) and when i tried to open just a dot are visible and when i tried to open jpg(converted to 0byte size) files they are not opened.
Expected scenario Image must be visible Action taken to solved Make the image size small convert images into from .png to jpg I stuck to this problem so please help me. Appreciate, if anyone can help to troubleshoot.
回答1:
nobody takes this question seriously but after do lots of type stuff i got the solution. Actually problem was with proguard, i don't known why but it works after set false to shrinkResources
release {
..
minifyEnabled true
shrinkResources false
}
回答2:
It`s the bad practce, you should use official google strategy as described here https://developer.android.com/studio/build/shrink-code#keep-resources
来源:https://stackoverflow.com/questions/41779849/android-images-are-not-displayed-after-release-build-or-if-i-instant-run-turn-of