Android gradle and libraries export order

I’m trying to migrate my project from ANT to Gradle, and i have stumbled upon a certain issue.

I need to access android @hidden field (without reflection), so far i have had a custom built java class (example: ConnectivityManager to get TYPE_WIFI_P2P). Note that this custom class was used only as a reference (excluded from actual apk).

The problem is that the Gradle is accessing the ‘unmodified’ ConnectivityManager class (provided by the android sdk) instead of the custom one. Is there a way to shadow it?

In Ant to do this i had the following:

<path id="project.javac.exclude.classpath">
    <path refid="my.custom.android.sdk"/>
    <path refid="the.original.android.sdk"/>
</path>
  <javac ... bootclasspathref="project.javac.exclude.classpath" ...>

With this i was able to use ‘modified’ ConnectivityManager.

How do I reproduce this behaviour using Gradle?

Gradle doesn’t support explicit classpath ordering generally. This is mainly as a performance optimisation and that relying on classpath ordering is very fragile (i.e. your application will break in certain environments).

That said, there are some tricks you can pull. As the Android SDK is involved here, you will be better of asking on the adt-dev group list.