2

我的清单有这个问题。

看起来这可能是一个骗局: Using @string for android:authorities in a ContentProvider

我有一个为不同版本的应用程序提供单独权限的提供程序(以便可以将不同的变体存储在不同目标 res 文件夹的字符串文件夹中。

我的清单如下所示:

   <provider android:authorities="@string/app_provider_auth" android:name="com.mecompany.myapp.provider.CachedFileProvider"/>

Bad Manifest现在,这工作正常,但是当它安装在 2.1 OS 设备上时我看到了一个问题。这是问题,因为当我将其更改为文本字符串时,它在 2.1 上运行良好。

我认为在 2.1 (7) 或更早版本中,清单不允许您从资源文件中引用字符串。那么,我可以为版本 7 创建一个单独的清单吗?我可以在清单中添加一个 if 语句吗?还是我必须提高 minSDK(最后的手段)?

更新:

确定进一步搜索似乎我可以使用我的 Maven 构建设置/切换提供者身份验证字符串。我已经有许多配置文件并且正在覆盖资源文件夹。所以我对这个想法很满意,但它是我无法理解的。就像是

<replaceAuthority>${customerauthority}<replaceAuthority>

但是我不知道我应该使用什么标签,或者我上面假设的方式是否是我需要走的方式。

4

2 回答 2

3

要从 maven 更改提供者,您可以使用<providerAuthorities>如下标签:

    <plugin>
        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <version>3.5.0</version>
        <extensions>true</extensions>
        <configuration>

            <!-- Установка версии в манифест -->
            <manifest>
                <versionName>${project.version.name}</versionName>
                <versionCode>${project.version.code}</versionCode>

                <!-- провайдер -->
                <providerAuthorities>
                    <property>
                        <name>.database.DatabaseProvider</name>
                        <value>${project.package}.database.DatabaseProvider</value>
                    </property>                        
                </providerAuthorities>

            </manifest>
        </configuration>
    </plugin>
于 2013-04-12T06:15:56.857 回答
1

从这里获得更多帮助android-maven-plugin 和资源过滤

这里https://github.com/jayway/maven-android-plugin/pull/115

和@Konstantin Pridluda 我得出了一个可以接受的结论。

我所做的是在父项目文件夹中创建一个名为 manifests 的新文件夹。然后创建了两个子文件夹 customer1Manifest 和 customer2Manifest

在每个文件夹中,我创建了清单文件的副本,然后将 @string 引用替换为适当的硬字符串权限。(正常的清单文件是调试授权)

然后在 POM 中,我将清单切换为像这样的适当清单。

<profiles>
    <profile>
     <id>Customer1</id>
     <activation>
         <activeByDefault>true</activeByDefault>
     </activation>
     <properties>
  <customerManifest>../manifests/customer1Manifest/AndroidManifest.xml</customerManifest>
      </properties>
    </profile>
    <profile>
     <id>Customer2</id>
     <properties>
        <customerManifest>../manifests/customer2Manifest/AndroidManifest.xml</customerManifest>
      </properties>
      </profile>
</profiles>

然后后来在 android-maven-plugin 阶段这样做了

 <plugin>
        <groupId>com.jayway.maven.plugins.android.generation2</groupId>
        <artifactId>android-maven-plugin</artifactId>
        <extensions>true</extensions>

        <inherited>true</inherited>
        <configuration>
         <androidManifestFile>${customerManifest}</androidManifestFile>
            .........
.......
        </configuration>
</plugin>
于 2012-10-26T14:56:07.857 回答