发布版本生成后或如果我立即运行,Android图像将不显示关闭 [英] Android Images are not displayed after release build or if i instant run turn off

查看:114
本文介绍了发布版本生成后或如果我立即运行,Android图像将不显示关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码,使用 getIdentifier 方法在运行时从drawable-hdpi获取图像ID

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)

我也尝试了以下方法

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());

当我打开android studio的即时运行功能时,两者均可工作,但不幸的是,当我关闭android studio的即时运行功能时,它们都不起作用. 我在调试以及使用以下代码的发布时间时都在使用Proguard

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'
        }

观察到的情况 图片未显示.代码运行完美,并在即时运行时显示图像. 我进行发布构建,然后对其进行反编译,我观察到res/drawable-hdpi文件夹中存在images(.png扩展名),但是大小转换为1 * 1尺寸(67byte),当我尝试打开一个点时可见当我尝试打开jpg(转换为0byte大小)文件时,它们没有打开.

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.

预期的情况 图片必须可见 为解决问题而采取的行动 缩小图像 将图像从.png转换为jpg 我坚持这个问题,所以请帮助我.谢谢,如果有人可以帮助您进行故障排除.

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.

推荐答案

没有人认真对待这个问题,但是在做了很多类型的工作之后,我得到了解决方案.实际问题出在proguard上,我不知道为什么,但是在将 false设置为rinkeResources

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

        }

这篇关于发布版本生成后或如果我立即运行,Android图像将不显示关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆