Add Dependency to module - External Library Error - android

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:
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:
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'

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)

Related

Android Import library error DefaultGroovyMavenDeveloper

I'm a newbie android app developer using android studio, and I am trying to use sticky list headers from https://github.com/emilsjolander/StickyListHeaders. I do this by File -> New -> Import Module and I add the dependency. However I am getting the error
Error:No such property: GROUP for class: org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer
My project build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "testingapp.dylanzammit.com.anothernewproj"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'se.emilsjolander:stickylistheaders:2.7.0'
}
If you want to add the libraries to your project in Android studio, you can do it in three different ways. Please read this link https://stackoverflow.com/a/35369267/5475941. In this post I explained how to import your JAR files in Android studio and I explained all possible ways step by step with screenshots. I hope it helps.

I added a new Library which was downloaded fro github and import with my project in android?

First i was created a folder to right click on my rootProject and create a direcotry(name library) and then i paste my downloaded library into library directory
here is my settings.gradle
include ':app'
include ':libraries:touchView'
and then i got to File->ProjectStructure>+ then dependancy tab and click on**+** select module dependany and select and press ok
here, is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.domore.loadlibrary"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':libraries:touchView')
}
for few second my build.gradle file is sync after it gave me an error which is listed below
configuration with the name 'default' not found
i also seen this video on youtube
https://www.youtube.com/watch?v=1MyBO9z7ojk
please, helm me to solve this problem

Failed to resolve:com.loopj.android:android-async-http:1.4.8

I have downloaded jar file of Loopj library and placed it in libs folder. have tried many changes but getting same error. Can anyone please help me to solve this.
build.gradle :-
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.example.pratik.receivedsms"
minSdkVersion 16
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.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.loopj.android:android-async-http:1.4.8'
}
What worked for me is opening gradle terminal from android studio and executing the following command:
gradlew installarchives
It should also work without downloading the jar file.
Another note is that I am using version 1.4.5.
Good luck!

Gradle DSL method not found:android()

Error:(1, 0) Gradle DSL method not found: 'android()'
Possible causes:
The project 'MyApp1' may be using a version of Gradle that does not contain the method.
Gradle settingsThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Root/build.gradle
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
applicationId "com.example.shark.gpsapp"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
}
App/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.example.shark.myapp"
minSdkVersion 15
targetSdkVersion 21
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'
}
I coudln't open any of my old projects.Please do suggest a answer.
I got this error after android studio update.
You cannot call android until after you apply the android plugin com.android.tools.build:gradle.
The gradle build file uses a DSL based on Groovy, a Java-like dynamic language. android { ... } is a call to a method named android, passing the block. The message you are getting indicates that the method android has not been defined. It is defined in the plugin.
Somehow, your root level build.gradle file is a near duplicate of your app level build.gradle. It should not be so.
I suggest that you create a completely new project, using Android Studio, and copy it's root level build.grade file to the existing project.

Not able to communicate between two modules in an Android project?

My project have two modules:
App
Facebook-lib
Here are my gradle files:
setting.gradle
include ':app', ':facebook-lib'
Module App gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 18
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.1.1'
compile project (':facebook-lib')
}
Module Facebook-lib gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 18
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.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
Whenver I am trying to access Facebook-lib class in App module. It works but I can't do vice versa.
I get com.app.testpackage doesn't exist or cannot find symbol class.
What I am doing wrong here?
You can't achieve it.
Your Module App has a dependency with the Module Facebook library. It means that you can use the classes inside the library in your main module.
Your Facebook library doesn't have a dependency with your module. It means that you can't use the classes in main module.
Also you can't create a circular dependency.

Categories

Resources