Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Dependency to module - External Library Error

I've created an external library that I was hoping to make open source. I import it as a module without issue.

I have to resolve this issue after import: enter image description here

Adding the dependency is what I want to do. I don't want to move it to :app.

When I add the dependency, the issue goes away. The import references the correct file. On build I get this issue: enter image description here

I figure the solution has to be with referencing the java file in the build.gradle file for the external library but I couldnt find any good examples or even proof that this would resolve the issue.

library is the module name.

Thanks in advance.

Edit: build.gradle for the app

apply plugin: 'com.android.application'

android {
  compileSdkVersion 22
  buildToolsVersion "23.0.0 rc3"

  defaultConfig {
    applicationId "com.weaverprojects.toundertest1"
    minSdkVersion 21
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.google.android.gms:play-services-gcm:7.5.0'
}

build.gradle for library

apply plugin: 'com.android.library'
android {
  compileSdkVersion 22
  buildToolsVersion "23.0.0 rc3"

  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
  }
}
  dependencies {
  //compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.2.1'
  compile 'com.google.android.gms:play-services-gcm:7.5.0'
 }

Settings.gradle

include ':app', ':library'
like image 744
Keith Avatar asked Mar 20 '26 12:03

Keith


1 Answers

Assuming that your library exists as it's own project, and it'd path relative to the top level folder for your main project is ../mylibs/library/ I think your settings.gradle should change as follows:

project(':library').projectDir = new File('../mylibs/library/');

and the following needs to go inside the dependencies section of your main/app/build.gradle file (which I think is the first code dump in your question).

compile project(':library')

BTW, please consider renaming :library to something else (this is not the source of the problem but the name can be confusing when you look at it some months later)

like image 140
e4c5 Avatar answered Mar 22 '26 00:03

e4c5