WebView.setWebContentsDebuggingEnabled(false)但我可以在安装签名APK后调试代码

时间:2014-08-28 19:17:07

标签: android cordova apk

我正在尝试发布我用cordova创建的Android应用程序,并在发布时我按照所有步骤如android:debuggable =“false”甚至删除此行作为其最新建议但问题是我安装签名的构建版本在我的模拟器中,我能够调试它......任何帮助?

更新: -

根据建议,我试过..

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

in public void onCreate(Bundle savedInstanceState){}

在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文件

2 个答案:

答案 0 :(得分:4)

您的代码中存在错误。无论应用程序是否标记为可调试,它都可以无条件地在KitKat和更新版本的所有应用程序的WebView中进行调试。

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

答案 1 :(得分:0)

您必须将您的网页视图设置为不可调试: WebView.setWebContentsDebuggingEnabled(false)。我查了一下:

public class HTML5Application extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        //webView.setWebChromeClient(new WebChromeClient());
        super.onCreate(savedInstanceState);
        super.init();
        // Set by <content src="index.html" /> in config.xml
        super.loadUrl(Config.getStartUrl());
        //super.loadUrl("file:///android_asset/www/index.html")

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
            Log.i("xxxxxx", "Enabling web debugging");
            OnlyForKitKat.enableWebViewDebugging();
        }

        appView.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) return true;
                return false;
            }
        });
    }

@SuppressLint("NewApi")
public class OnlyForKitKat {

    public static void enableWebViewDebugging() {
        WebView.setWebContentsDebuggingEnabled(false);
    }

}
  

enter image description here