问题
I have an Android app built on top of the Ionic/Cordova platform. By default Remote Android Debugging is enabled.
https://developers.google.com/web/tools/chrome-devtools/remote-debugging/
This means that if the device is connected to a computer, one can go open the Chrome browser, go to chrome://inspect find a list of webpages, or app's with webviews, click inspect and see the apps HTML, JS and other resources. This is fine for debugging but I'd like this disabled in the released app.
In trying to disable this (or find where its been enabled) I found theres a function
@TargetApi(Build.VERSION_CODES.KITKAT)
private void enableRemoteDebugging() {
try {
WebView.setWebContentsDebuggingEnabled(true);
} catch (IllegalArgumentException e) {
LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
e.printStackTrace();
}
}
in SystemWebViewEngine.java in the Cordova directory.
https://github.com/apache/cordova-android/blob/37384c583d5a2e5b9b5c5d2cbf150f07f329d16c/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java
Is there a configuration that can be set or another way for this to be disabled?
回答1:
When you release the App signed, the debugging is disabled. You can check by running the app with:
cordova run android --release -- --keystore=../my-release-key.keystore --storePassword=password --alias=alias_name --password=password
Signing an App
Or you can set android:debuggable="false"
in the <application>
of your AndroidManifest.xml
, and just run the app with: cordova run android
chrome-remote-debugging
回答2:
android webview is not debugable by default. Cordova open debuging when the application is debugable which is configed in AndroidManifest.xml.The code is below:
public class SystemWebViewEngine implements CordovaWebViewEngine {
private void initWebViewSettings() {
ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 &&
android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
enableRemoteDebugging();
}
}
}
So webview in ionic is debugable in debug build and not debugable in release build.
来源:https://stackoverflow.com/questions/40641095/how-to-disable-remote-android-debugging-of-webview-in-ionic-cordova