【问题标题】:WebView.setWebContentsDebuggingEnabled(false) but I am able to debug the code after installing the signed APKWebView.setWebContentsDebuggingEnabled(false) 但我可以在安装签名的 APK 后调试代码
【发布时间】:2014-08-28 19:17:07
【问题描述】:

我正在尝试发布使用 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 文件

【问题讨论】:

  • 你是如何调试旅游代码的?
  • 通过 chrome 设备工具

标签: android cordova apk


【解决方案1】:

您必须将 webview 设置为不可调试: 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);
    }

}

【讨论】:

  • chrome:://inspect 不显示调试页面。你可以禁用条件 if(0 != (getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE)){ ?
  • 非常感谢...但只是禁用条件并不能解决调试问题
  • 禁用该条件并不能解决 GenyMotion 中的调试问题,但在设备中它也可以按预期在此条件下正常工作。甚至 wikipedia 的应用程序也可以在 genymotion 中调试。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    相关资源
    最近更新 更多