Glide: Glide Configuration: Unable to find GlideModule implementation when you have build flavours

Created on 13 Aug 2015  路  3Comments  路  Source: bumptech/glide

Hello I am trying to implement a Glide configuration to set PREFER_ARGB_8888 however my Android project contains two build flavours (with two different package names)

i.e. com.myapp and com.myapp.development

Here is what I have tried

  <meta-data android:name="${applicationId}.utils.GlideConfiguration" android:value="GlideModule"/>
  <meta-data android:name=".utils.GlideConfiguration" android:value="GlideModule"/>

And here is my glide configuration class

public class GlideConfiguration implements GlideModule{
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        builder.setDecodeFormat(DecodeFormat.PREFER_ARGB_8888); 
    }

    @Override
    public void registerComponents(Context context, Glide glide) {

    }
}

I do not have pro-guard enabled

This is the exception i get

 java.lang.IllegalArgumentException: Unable to find GlideModule implementation
question

Most helpful comment

Local names (starting with .) only work in certain places, see table in documentation also the ${applicationId} will only work if your classes are in the same package as applicationId's name is. applicationId and package name are different species, most likely your flavor has a suffix .flavor1 which means that the GlideConfiguration class has to be in main.package.flavor1.util. You have two alternatives:

Same package

src/main/AndroidManifest.xml:

<meta-data android:name="package.name.for.main.code.GlideConfiguration" android:value="GlideModule" />

And create two files:

src/flavor1/java/package/name/for/main/code/GlideConfiguration.java
src/flavor2/java/package/name/for/main/code/GlideConfiguration.java

src/main/java/package/name/for/main/code/GlideConfiguration.java shouldn't exist

Different Packages

Create a src/<flavor>/AndroidManifest.xml for each flavor:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application>
         <meta-data android:name="package.name.for.flavor.GlideConfiguration" android:value="GlideModule" />
    </application>
</manifest>

And create two files:

src/flavor1/java/package/name/for/flavor1/GlideConfiguration.java
src/flavor2/java/package/name/for/flavor2/GlideConfiguration.java

src/main/java/package/name/for/main/code/GlideConfiguration.java can co-exist but you have to register it in src/main/AndroidManifest.xml. This way you can have global config and per-flavor config (you can have as many GlideModules as you want).

All 3 comments

Local names (starting with .) only work in certain places, see table in documentation also the ${applicationId} will only work if your classes are in the same package as applicationId's name is. applicationId and package name are different species, most likely your flavor has a suffix .flavor1 which means that the GlideConfiguration class has to be in main.package.flavor1.util. You have two alternatives:

Same package

src/main/AndroidManifest.xml:

<meta-data android:name="package.name.for.main.code.GlideConfiguration" android:value="GlideModule" />

And create two files:

src/flavor1/java/package/name/for/main/code/GlideConfiguration.java
src/flavor2/java/package/name/for/main/code/GlideConfiguration.java

src/main/java/package/name/for/main/code/GlideConfiguration.java shouldn't exist

Different Packages

Create a src/<flavor>/AndroidManifest.xml for each flavor:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <application>
         <meta-data android:name="package.name.for.flavor.GlideConfiguration" android:value="GlideModule" />
    </application>
</manifest>

And create two files:

src/flavor1/java/package/name/for/flavor1/GlideConfiguration.java
src/flavor2/java/package/name/for/flavor2/GlideConfiguration.java

src/main/java/package/name/for/main/code/GlideConfiguration.java can co-exist but you have to register it in src/main/AndroidManifest.xml. This way you can have global config and per-flavor config (you can have as many GlideModules as you want).

Thank you

I've tried both alternatives but still having the same issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Anton111111 picture Anton111111  路  3Comments

Tryking picture Tryking  路  3Comments

billy2271 picture billy2271  路  3Comments

MrFuFuFu picture MrFuFuFu  路  3Comments

mttmllns picture mttmllns  路  3Comments