Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView.setWebContentsDebuggingEnabled(false) but I am able to debug the code after installing the signed APK

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?

Update:-

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

in public void onCreate(Bundle savedInstanceState){}

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
            }

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

like image 855
Luckyy Avatar asked Aug 28 '14 19:08

Luckyy


1 Answers

You have to set your webview not debuggable: WebView.setWebContentsDebuggingEnabled(false). I have checked:

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

and

@SuppressLint("NewApi")
public class OnlyForKitKat {

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

}

enter image description here

like image 99
malcubierre Avatar answered Sep 28 '22 08:09

malcubierre