本文介绍了WebView.setWebContentsDebuggingEnabled(false) 但我可以在安装签名的 APK 后调试代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发布使用cordova创建的android应用程序,在发布时我遵循了所有步骤,例如android:debuggable="false",甚至删除了这一行作为其最新建议,但问题是当我安装已签名的构建版本时在我的模拟器中我可以调试它......有什么帮助吗?

I am trying to publish my android app created with cordova and while publishing I followed all steps like android:debuggable="false" or even removing this line as its the latest suggestion but the problem is when I install the signed build version in my emulator I am able to debug it ... any help?

更新:-

根据建议,我尝试了..

As per suggestion I tried ..

public class appname extends CordovaActivity 
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        super.init();
        super.loadUrl(Config.getStartUrl());
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
            if(0 != (getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE)){
                //Log.i("Your app", "Disable web debugging");
                WebView.setWebContentsDebuggingEnabled(false);
            }
        }
    }
}

在公共无效 onCreate(Bundle savedInstanceState){}

in public void onCreate(Bundle savedInstanceState){}

在 CordovaWebView.java 中找到这段代码

Found this piece of code in CordovaWebView.java

if((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 &&  
                android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT)
            {
                setWebContentsDebuggingEnabled(true); // I tried setting this false as well
            }

但它仍然无法正常工作...我仍然能够调试 html js 文件

But its still not working...am still able to debug html js files

推荐答案

您的代码中存在错误.无论应用是否标记为可调试,它都会无条件地在 KitKat 和更新版本上的所有应用的 WebView 中启用调试.

There's a bug in your code. It unconditionally enables debugging in all your app's WebViews on KitKat and newer, regardless of whether the app is marked as debuggable.

0 != (getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE) 实际上应该是 0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE).

这篇关于WebView.setWebContentsDebuggingEnabled(false) 但我可以在安装签名的 APK 后调试代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:43