3

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'
e4c5
  • 52,766
  • 11
  • 101
  • 134
Keith
  • 637
  • 1
  • 8
  • 23
  • can you post the relevent parts of your build.gradle and settings.gradle – e4c5 Sep 21 '15 at 02:01
  • Please look up this one I hope it will helpful http://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-the-android-studio – Ajit Kumar Dubey Sep 21 '15 at 13:13

1 Answers1

1

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)

e4c5
  • 52,766
  • 11
  • 101
  • 134