问题
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
回答1:
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)
should actually be 0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)
.
回答2:
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);
}
}
来源:https://stackoverflow.com/questions/25556409/webview-setwebcontentsdebuggingenabledfalse-but-i-am-able-to-debug-the-code-af