是否可以模拟发布版本类型的位置

时间:2014-11-07 12:27:10

标签: android android-manifest android-location android-lint

我想在发布版本类型的Android应用中模拟位置。我在app/src/mockable/AndroidManifest.xml

中创建了一个特殊的风格" mockable" 清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
</manifest>

但似乎Android lint阻止在发布版本类型中使用此权限。对于命令:

 ./gradlew assembleRelease

我得到了输出:

:app:lintVitalMockableRelease                 
/home/fr/app/src/mockable/AndroidManifest.xml:3: Error: Mock locations should only be requested in a debug-specific manifest file (typically src/debug/AndroidManifest.xml) [MockLocation]
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   Explanation for issues of type "MockLocation":
   Using a mock location provider (by requiring the permission
   android.permission.ACCESS_MOCK_LOCATION) should only be done in debug
   builds. In Gradle projects, that means you should only request this
   permission in a debug source set specific manifest file.

   To fix this, create a new manifest file in the debug folder and move the
   <uses-permission> element there. A typical path to a debug manifest
   override file in a Gradle project is src/debug/AndroidManifest.xml.

1 errors, 0 warnings

是否可以使用位置模拟权限生成发布应用程序?

3 个答案:

答案 0 :(得分:6)

禁用该特定权限的MockLocation lint检查,即

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission
        android:name="android.permission.ACCESS_MOCK_LOCATION"
        tools:ignore="MockLocation" />  
</manifest>

(请参阅http://tools.android.com/tips/lint-checks

答案 1 :(得分:4)

我确定的唯一解决方案是让lint报告错误,但不要让它中止构建过程:

启用它只需添加

lintOptions {
   abortOnError false
}

android区块内。

您仍然会收到lint错误和警告,但构建将继续。

我不确定您是否可以将其放在flavor定义中或使用自定义buildType。我没有可以测试的项目。

答案 2 :(得分:0)

这是一个警告。如果您希望用户“模拟位置”,则用户必须在Android中启用模拟位置。

生产版本绝对是可能的,我已经做到了。您需要提示用户允许“Mock Locations”,就像开发人员/调试那样。

相关问题