Unable to add library to Android Studio project - java

I'm trying to add this library to Android Studio locally using this tutorial on YouTube.
However, I get errors that I can't post here because they're too many (99+).
Can someone tell me step by step (in detail) how to succesfully add this library to my project and be able to edit it afterwards?
This is the main error I get when I try to import this library: `Unable to determine constructor argument #1: missing parameter of type Factory, or no service of type Factory.
My build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Here is your step-by-step guide:
Create an empty project or open your existing project where you want to add this library.
Clone the library project from the git or download the zip and extract it in some other directory.
Now, in Android Studio, go to File -> New -> Import Module.... Select the cloned/extracted library directory. Make sure the :placepicker module is selected for import. Then click Finish.
Now copy two files bintray.gradle and install.gradle from cloned/extracted project root directory to your own project root directory. Add this point your project structure should look like this:
Now open your project level build.gradle. Add ext.kotlin_version = '1.3.72' inside buildscript { and also add following dependencies:
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
Overall, this will look like:
Finally, go to File -> Sync Project with Gradle Files. It will take some time to download the missing dependencies and you have now successfully integrated the library within your project which is fully editable.
Now to make this library work in your own app module, in the build.gradle file of your app module, add this inside dependencies section:
api project(':placepicker')

Or edit your gradle.build like in the picture:

Step by step description:
Then ceck out the git project to your machine.
Modify and build it with a new Version.
Add the dipendency as Jar from Your local filesystem in Android Studio.
Try this:
File > Project Structure > Dependencies Tab > Add module dependency (scope = compile)
Where the module dependency is the project library Android folder.

In build.gradle(Module.app) file add this.
implementation 'com.google.android.gms:play-services-places:17.0.0'
let me knew if it's work.

Related

Publish Android library with external dependencies

I have an Android closed source module that will be be used as a library in other projects. It contains external dependencies.
To publish it, I'm creating a Maven artifact with the following gradle task:
apply plugin: 'maven'
def coreAarFile = file('...build\\outputs\\aar\\android-sdk-release.aar')
artifacts {
archives coreAarFile
}
uploadArchives {
repositories.mavenDeployer {
repository(url: "file://.\\mvn-repo")
pom.project {
groupId 'a.blabla'
artifactId 'blabla-sdk'
version "1.0.0"
}
}
}
It generates the .aar file, the pom.xml, etc without problems.
Then I create a project that have a dependeny to my library declared. It works until it needs to access to the external dependencies, when throws a class not found exception.
How can I edit my gradle task to include external dependencies or at least a reference to them? They are published in mvnrepository.com and github.com.
I moved uploadArchives to the build.gradle of the module and removed the artifacts element. It works!
Thanks to CommonsWare for pointing to the right direction.

Missing Android-support-v7-appcompat in my Android project in Eclipse

I am trying to import an Android project in Eclipse., but after importing the project, I am getting errors which say "Missing android-support-v7-appcompat", "Missing Facebook SDK","Missing Google Play services lib" and "Missing library".
I can understand that I am missing libraries but do not have any clue how to add those libraries, as I am new in Android development environment.
Here, is a screenshot of the error http://screencast.com/t/iWXLkK8glkF
Delete the extra apply in the first line of your gradle file...
UPDATE:
You know how you have two gradle files? One for your application (The one you are working on right now) and the other one which is a top level build.gradle file? Put the below code in the top level build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}

Where is project.properties in Android Studio project

I was following this instructions to add a library in android studio. The last step is to add the line manifestmerger.enabled=true in project.properties. I have few .properties files such as local.properties, gradle.properties, cache.properties but I can't find project.properties file.
The step you're talking about is for Eclipse not Android Studio, which you have to follow only the first two instructions:
Step 1. Configure your app’s build.gradle File
Make sure you have a jcenter() entry in your repositories like so:
repositories {
jcenter()
}
add the library AAR as a dependency like so:
dependencies {
compile 'org.altbeacon:android-beacon-library:2+'
}
project.properties is a Eclipse thing and Android studio does not use project.properties file. If you need one, it has to be manually created. But it will not be used by Android Studio.
You can create this file manually in project root directory, near other ".properties" files.

How to implement a global resource folder for a mutli-project gradle project?

I have the following project:
-> root
->->common
->->server
->->client
I want the server and client projects to both access files from the same resource folder.
My root's build.gradle looks like the following:
apply plugin: 'java'
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
}
subprojects {
repositories {
mavenCentral()
}
dependencies {
testCompile 'junit:junit:4.8.1'
}
}
The multi-project system works and I have no issues with it. I have found resources for implementing resource folders but they're only at a per-project level.
I'd appreciate any insight and help in this. :)
If you have resources you want shared across projects you should create a library for those resources, and have each project depend on that library. Take a look at the Android documentation on library modules.
Also, take a look here for an example of how to add a project dependency to your Gradle build script.
In case you prefer not to have another artifact then another option would be to merge the client/server code with the common code before building (e.g. $buildDir/src) and pointing the srcDir to this location.
In order to do this:
Add a prepareSources task of type Copy that will copy all relevant sources both from client/server and common into alternative src/main folder (e.g. under $project.buildDir/src)
Rename the src/main folder in the server/client modules to something else. This is needed as the java plugin automatically includes this folder in srcDir while we want to take these sources from the merged sources location.
Make compileJava and processResources dependent on the new prepareSources task:
compileJava.dependsOn prepareSources
processResources.dependsOn prepareSources
Add the new src directory to srcDir

Android Studio reuse module library at other project

I have a module with some POJO classes that is marked at gradle as apply plugin: 'java' .Is there a way to reuse it at another project ? Everything i tried failed . (I dont want to copy pasta it)
I was facing the same issue recently.
This is how I resolved the code redundancy problem:
Create a new Android Studio project 'libs' and add all my APIs in a 'library' module.
In build.gradle of your library module, add code to upload the artifact to local Maven repo.
`
apply plugin: 'maven'
group = 'com.<example>'
version = '1.0'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file:///Users/<myuser>/.m2/repository")
}
}
}
`
The archive is uploaded in your maven repo as aar file.
Use this aar file in any other project as a dependency.
Hope this helps.
Here are two other questions on the same matter.
How do I add a library project to Android Studio?
How to create a library project in Android Studio and an application project that uses the library project
Personally I didn't use any of the two provided methods.
I built my project as a JAR, added it to the 'libs' folder, right clicked on it and clicked 'Add as library' and then finally added the dependency in the gradle file like so:
dependencies {
compile files('libs/MyJAR.jar')
}

Categories

Resources