aapt wants minSDKVersion to be a string

209 views
Skip to first unread message

Dirk Jäckel

unread,
Oct 8, 2012, 10:42:36 AM10/8/12
to adt...@googlegroups.com
Hi!

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:
------ SNIP --------


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


[…]
</manifest>
------ SNIP --------

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

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


------ SNIP --------




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:
------ SNIP --------


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


[…]
</manifest>

------ SNIP --------

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

------ SNIP --------
<resources>
<string name="minSdkVersion">8</string>
</resources>
------ SNIP --------



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)

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.


Regards,
Dirk







Xavier Ducrohet

unread,
Oct 8, 2012, 12:01:59 PM10/8/12
to adt...@googlegroups.com
you cannot reference a resource in the minsdkVersion of your manifest.

If you want to inject a different version at build time you will have to do it with a script yourself.

The next build system will make this very easy but there's no feature of the current build system to help you with this.
--
Xavier Ducrohet
Android SDK Tech Lead
Google Inc.
http://developer.android.com | http://tools.android.com

Please do not send me questions directly. Thanks!

Dirk Jäckel

unread,
Oct 8, 2012, 7:00:43 PM10/8/12
to adt...@googlegroups.com
Thanks for the fast clarification!

In case someone is interested in my solution:

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}

Regards,
Dirk

PS: This question and answer is also on stack overflow:
http://stackoverflow.com/questions/12784610
With another solution by Mark Murphy.

Manfred Moser

unread,
Oct 9, 2012, 12:12:23 AM10/9/12
to adt...@googlegroups.com
Nice solution Dirk ;-)
Reply all
Reply to author
Forward
0 new messages