“aapt dump badging” wants minSdkVersion to be a string but “adb install” needs it as an integer

StackOverflow https://stackoverflow.com/questions/12784610

  •  05-07-2021
  •  | 
  •  

Pregunta

I need to have a different minSDKVersion in the Google Play Store (for device filtering purposes) than for private beta testing. I tried the following:

AndroidManifest.xml contains the following:

<manifest …>
[…]
    <uses-sdk android:minSdkVersion="@integer/minSdkVersion" android:targetSdkVersion="15"/>
[…]
</manifest>

res/values/config.xml is generated by maven and contains the following:

<resources>
  <integer name="minSdkVersion">8</integer>
</resources>

This works fine except for aapt dump badging which complains:

ERROR getting 'android:minSdkVersion' attribute: attribute is not a string value

Unfortunately aapt dump does not dump the rest. So I am left with no output except this error :-(

When I change the minSdkVersion reference to a string reference like this:

AndroidManifest.xml contains the following:

<manifest …>
[…]
  <uses-sdk android:minSdkVersion="@string/minSdkVersion" android:targetSdkVersion="15"/>
[…]
</manifest>

res/values/config.xml is generated by maven and contains the following: 8

With this I cannot install the app because somehow my device with API Level 16 (Jelly Bean) does not allow APKs with

sdkVersion:'8'

(according to aapt dump badging) to be installed. The error is: INSTALL_FAILED_OLDER_SDK

It seems the string reference is somehow misinterpreted while creating the APK.

What can I do to have android:minSdkVersion referenced from a resource-file and debug it with aapt?

aapt version is 0.2 from Android Tools Rev. 20.

¿Fue útil?

Solución 2

Since I am already using Maven to build the project I solved the problem this way:

I moved the AndroidManifest.xml to a folder called: ${project.basedir}/filtered and replaced the minSdkVersion value in the AndroidManifest.xml with a property reference (I already had this in the pom.xml): ${project.property.minSdkVersion}:

<uses-sdk android:minSdkVersion="${project.property.minSdkVersion}" android:targetSdkVersion="15"/>

and removed it from the filtered/config.xml. Then I added the following resource-filtering directive to the pom.xml:

<project ...>
  ...
  <properties>
    <project.property.minSdkVersion>8</project.property.minSdkVersion>
  </properties>
 ...
 <build>
  <resources>
    <resource>
     <filtering>true</filtering>
     <directory>${project.basedir}/filtered</directory>
     <targetPath>${project.basedir}/</targetPath>
     <includes>
        <include>AndroidManifest.xml</include>
     </includes>
   </resource>
  </resources>
  ...
 </build>
 ...
</project>

This way the filtered AndroidManifest.xml is at the place where Eclipse expects it and has the property reference replaced after calling mvn process-resources. In the other profiles I have different values for ${project.property.minSdkVersion}

Otros consejos

Quoting Xav in his response to the dupe of this question asked on the adt-dev Google Group:

you cannot reference a resource in the minsdkVersion of your manifest.

While a lot of things in the manifest can reference resources, apparently minSdkVersion cannot.

Xav suggests using a script to change the manifest. Another approach would be to package the bulk of your app as an Android library project and creating two apps that use the library, one with each of your two minSdkVersion values.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top