Search code examples
androidandroid-gradle-pluginandroid-library

Why support-v4 dependency not added runtime in my Custom Library


I am going to make custom library. After Making aar, import it in another, Support dependency not found.

My Library Gradle is:

dependencies {
     implementation fileTree(include: ['*.jar'], exclude: ['classes2.jar'], dir: 'libs')
     compileOnly files('libs/classes2.jar')

     implementation 'com.android.support:support-v4:27.1.1'
     implementation 'com.android.support:multidex:1.0.1'
}

Solution

  • The problem because you're using implementation:

    When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime.

    The module depends on the custom library will not see the support library. So, you need to use api:

    When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time. This configuration behaves just like compile (which is now deprecated), and you should typically use this only in library modules.

    Change your dependencies block to something like this:

    dependencies {
         implementation fileTree(include: ['*.jar'], exclude: ['classes2.jar'], dir: 'libs')
         compileOnly files('libs/classes2.jar')
    
         api 'com.android.support:support-v4:27.1.1'
         api 'com.android.support:multidex:1.0.1'
    }