Android Cordova 应用程序的条件编译

Conditional compile for an Android Cordova app

我有一个 Cordova/Android 混合应用程序,它使用一个自定义 - 内部 - 插件。除其他外,该插件会获取并显示 AdMob 广告。在我测试的调试版本中,我使用 Google 的测试广告使用

String deviceID = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ANDROID_ID);

AdRequest.Builder builder = new AdRequest.Builder();   
builder.addTestDevice(deviceID);

到目前为止没有问题 - 在我测试应用程序时,我看到了预期的安全测试广告。但是,我想防止有一天我创建发布版本并将其与该测试广告代码一起发送到 Play 商店。我想知道......有没有办法将该代码放入条件编译块中,该块仅在检测到有问题的构建是 Cordova 调试构建时才会分叉 - cordova build android --debug?

你可以试试this plugin

cordova-plugin-is-debug A cordova plugin to detect if the app is running in debug mode or not. Debug mode is when the app is built and installed locally via xcode / eclipse / the cordova cli etc, compared to release mode when the app was downloaded from the app / play store via an end user. Common use cases include:

using a different API endpoint for development using a different push notification certificate for development and production

那我猜你的插件必须在运行时使用这个插件