Android SDK 25:在早期版本的Android设备上出现涟漪图形错误

3

我是一个对Android编程和StackOverflow都很新的人。这是我的第一个问题,但我以前在这里和那里使用过StackOverflow平台来解决问题。现在我的问题是,我有一个Android应用程序,在SDK 11的所有Android设备上都可以正常运行。然而,在更新到SDK 25后,它会在早期的棒棒糖设备上崩溃。

我的日志如下:

Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering

我在gradle中添加了vectorDrawables.useSupportLibrary = true。我的minSdkVersion = 11targetSdkVersion = 25supportLibraryVersion = 25.2.0
我尝试了这里能找到的所有建议,但没有一个有效。所以请大家帮帮忙,我渴望学习,以便解决这个问题。
谢谢。

你使用的是哪个Gradle版本? - Anurag Singh
我正在使用Gradle版本3.3和插件版本2.3。 - Victor Okech
有没有一种实时聊天的方式,这样我们就能更快地解决这个问题。涉及到的活动是RecentActivityActivity。我在Skype上可用,用户名为victorokech。 - Victor Okech
@AnuragSingh,我找到了问题所在。我会发布我的解决方案,但它与之前我所认为的 Ripple Drawable 无关。感谢你的帮助,我的朋友。 - Victor Okech
1
你好@AnuragSingh,问题实际上是与Android权限有关。当我更新我的代码以适应权限时,我忘记了考虑到早期版本的设备,因此if语句之间的一部分代码在早期版本的设备上没有被执行。因此,某些视图未能加载,导致了空指针异常。我仍然不知道为什么会出现Ripple Drawable,但我明天会发布我的代码,让大家看看。 - Victor Okech
显示剩余10条评论
1个回答

2
调试有时会很痛苦,上面的问题是由我原始代码中一个简单的错误导致的。人都会犯错...
现在来看解决方案。我的初始代码如下,如果你仔细看,你会注意到在检查Build.Version的if语句之间的初始化代码不会在设备版本低于23的情况下运行。
        if(Build.VERSION.SDK_INT >= 23) {
        if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            // Storage permissions is already available, save profile photo

            initialization();
        } else {
            // Providing additional rational to the user if permission was not granted
            if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show();
            }

            requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE);
        }
    }

这是初始化方法。在Android版本低于23的设备上,它不会运行,从而触发Could not find class错误。然而,我仍然没有弄清楚这与Ripple Drawable有什么关系,因为我在代码中没有使用矢量可绘制对象。因此,任何阅读此内容的人可能会对原因有所启示。

    private void initialization() {

    hoverView = (View) findViewById(R.id.hoverView);
    hoverView.setVisibility(View.GONE);

    mExitAppDialog = new HookUpDialog(this);
    mExitAppDialog.setMessage(getString(R.string.exit_app_message));
    mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_OK,
            new OnClickListener() {

                @Override
                public void onClick(View v) {
                    mExitAppDialog.dismiss();

                    if (WallActivity.getInstance() != null) {
                        WallActivity.getInstance().finish();
                    }
                    sInstance.finish();

                    /* Informing the user, to press back again to exit */
                    Toast.makeText(getApplicationContext(),
                            R.string.press_back_again_to_exit,
                            Toast.LENGTH_SHORT).show();

                }
            });
    mExitAppDialog.setOnButtonClickListener(HookUpDialog.BUTTON_CANCEL,
            new OnClickListener() {

                @Override
                public void onClick(View v) {
                    mExitAppDialog.dismiss();

                }
            });
    mLlRecentActivity = (LinearLayout) findViewById(R.id.llRecentActivity);
    mNoActivitiesView = (TextView) findViewById(R.id.tvNoRecentActivities);
}

现在是完整的代码,包括针对Android版本23及以下设备的else if修复。

            if(Build.VERSION.SDK_INT >= 23) {
        if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
            // Storage permissions is already available, save profile photo

            initialization();
        } else {
            // Providing additional rational to the user if permission was not granted
            if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                Toast.makeText(this, "Storage permission is needed to save your profile photo.", Toast.LENGTH_LONG).show();
            }

            requestPermissions(new String[] {Manifest.permission.READ_CONTACTS}, WRITE_EXTERNAL_STORAGE);
        }
    } else if (Build.VERSION.SDK_INT < 23 ) {
        // Storage permissions is already available, save profile photo

        initialization();

    }

感谢 @Anurag Singh 的帮助,经过数小时的测试和反复测试,我终于看到了这个结果。不断地搜索和查找。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接