Google licence Verification Library not getting referenced, android-studio 0.8.2 - android-studio

Being new to android and android studio(0.8.2), I am trying hard to implement Google LVL for my project.
I have followed the link:- http://developer.android.com/google/play/licensing/setting-up.html and lots more help from web.
I want to add LVL as library project and I followed the steps mentioned in this link:--
How do I add a library project to Android Studio?
1) Created a new module for LVL.
2) copied the code from the downloaded com directory to the newly created modules com directory.
3)I have added the proper dependency using dependency tab on main project.
Following imports are not compiling.
import com.google.android.vending.licensing.LicenseChecker;
import com.google.android.vending.licensing.LicenseCheckerCallback;
If I verify my configuration files, all looks proper.
Following is my android.xml
`
<application android:allowBackup="true"
android:label="#string/app_name"
android:icon="#drawable/ic_launcher">
</application>
`
build file of this LVL module is:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
build file of the main app shows the added dependency:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':apkExpansion')
}
settings.gradle has, which also looks proper:
include ':app', ':licensing', ':apkExpansion'
project(':licensing').projectDir = new File('library/licensing')
project(':apkExpansion').projectDir = new File('library/apkExpansion')
My project as the following setup:
MyProject/
| settings.gradle
+ app/
| build.gradle
+ librarary/
+ licensing
| build.gradle
+ apkExpansion/
| build.gradle

After looking your files closely, I see the probable cause is the package name in Android.xml of LVL library module.
When you create a new module for any existing library, the package name should match the package of library or else if you wish, you need to edit all files package deceleration.
You need to compile your library module separately to see if everything goes well.
Also, other than com folder you need to copy the res folder to your library module to avoid any further issues.
Hope this helps.

Related

Android Studio - Too many libraries imported to project eventhough they are not compiled in dependencies

I am creating a new Android application that using Firebase. I followed goolge guide to add Firebase SDK to my project.
below are my project gradle:
buildscript {
repositories {
jcenter(){
url "http://jcenter.bintray.com/"
}
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And application build.gradle
....
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
/* For Google Play Services */
//Firebase
//addd firebase notification - messaging.
//add firbaes dynamic link:
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.google.android.gms:play-services-safetynet:9.0.2'
compile 'com.google.android.gms:play-services-auth:9.0.2'
compile 'com.firebaseui:firebase-ui:0.2.2'
compile 'com.google.firebase:firebase-messaging:9.0.2'
compile 'com.google.firebase:firebase-invites:9.0.2'
compile 'com.google.android.gms:play-services:9.0.2'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
I checked in External library of my project. There are too many library that I don't not need such as: play-service-location-9.0.2, play-service-maps-9.0.2, play-service--nearby-9.0.2...
enter image description here
Could you explain and help me reduce unused library that I don't added into my project ?
Try removing the dependencies you don't need by deleting the dependency from the build.gradle one by one, if you get an error after removing one of your dependencies, add the dependency you just removed back.
As long as you get no errors or problems when removing the dependencies you don't need, everything will be fine.

Download and commit gradle dependencies and plugins in Android Studio

This is an excerpt from a build.gradle file for one of my modules. I'm using android-studio-1.5.1 and gradle 2.10.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
}
I also have classpath 'com.google.gms:google-services:3.0.0' in the project level build.gradle file.
I'm trying to gather all the associated jars into a directory which I can commit to my git repo. Something like:
task copyRuntimeLibs(type: Copy) {
into "${projectDir}/libs"
from configurations.compile
}
(This does not work)
Also, I'm not trying to download the sources or javadocs.
I need to be able to commit all dependencies so that the project can be shared on an intranet without internet access.
I've written a plugin which will download all jars and poms. See the code here to download all jars and all poms from a Gradle Configuration
Note: There's a failing test here which shows that the parent pom's are not being downloaded. I've raised an issue here on Gradle's github.
I will likely improve the plugin to invoke the Maven Model Builder APIs to get the parent poms.
FYI - I've already integrated the ModelBuilder APIs successfully with Gradle (see here and here) so shouldn't be too difficult.

Where do i add my dependencies? In which build.gradle to put them?

I am requested to add a few dependencies. I know They should be added on build.gradle, but in the dependencies section is written:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I am new to android so from my small experience and googling there are supposed to be two build.gradle files, and only in one of them I should add dependencies, but I can not find an extra build.gradle file!?
I will be happy for help! Where should I add my dependencies and where did my second build.gradle disappear?
Gradle is a bit of an odd tool.
https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html
They state here how it works. There is only one build.gradle per project that will pull and manage dependencies for you.
Android Studio extends this. There is one 'main' build.gradle for the entire project, and then for each submodule there is a build.gradle since they are run as separate programs. in the master project build.gradle, put dependencies that effect everything you are doing in the build process, and then for each module dependencies specific for those modules. That's what it's saying.
http://developer.android.com/tools/building/configuring-gradle.html
**EDIT: **
Android Studio docs:
Declare dependencies
The app module in this example declares three dependencies:
dependencies {
// Module dependency
compile project(":lib")
// Remote binary dependency
compile 'com.android.support:appcompat-v7:19.0.1'
// Local binary dependency
compile fileTree(dir: 'libs', include: ['*.jar']) }
Each of these dependencies is described below. The build system adds all the compile
dependencies to the compilation classpath and includes them in the
final package.
Gradle docs:
Example 7.1. Declaring dependencies
build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
Dependencies can be listed in a bunch of different ways.

Android Studio: including AAR library from a library project

In my Android Studio project I have two subprojects/modules: an Android application (App1) and an Android library project (LibraryProject1). App1 depends on LibraryProject1. So far so good.
However, LibraryProject1, in turn, needs to import an AAR library to work properly.
So my Configuration is as follows:
App1 includes LibraryProject1
LibraryProject1 includes dependency.aar
Now, to include dependecy.aar I use the method detailed here:
How to manually include external aar package using new Gradle Android Build System
So basically in my build.gradle for LibraryProject1 I have:
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile (name:'dependency', ext:'aar') //my AAR dependency
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
}
Obviously, I put my dependency.aar file in the libs directory of LibraryProject1
However, this doesn't work. It seems that the repository added by LibraryProject1 is completely ignored and the local "libs" folder is not included as a repository, causing compilation to fail.
If I add the repository from the App1's build.gradle it works, but I don't want to do that, it's LibraryProject1 that needs the AAR file, not App1.
How can I do this??
Well, I found a way, but since it's very "hacky" I'll leave the question open, in case anyone comes up with a better, "proper" solution.
Basically the problem is that the flatDir repository is ignored at compilation time if included from LibraryProject1's build.gradle script, so what I do is I use App1's build.gradle to "inject" the flatDir repository in LibraryProject1. Something like this:
//App1 build.gradle
dependencies {
//get libraryproject1 Project object
Project p = project(':libraryproject1')
//inject repository
repositories{
flatDir {
dirs p.projectDir.absolutePath + '/libs'
}
}
//include libraryproject1
compile p
}
This effectively allows LibraryProject1 to include the external AAR library without having App1 include it. It's hacky but it works. Note that you still have to put:
//LibraryProject1 build.gradle
repositories {
flatDir {
dirs './libs'
}
}
inside LibraryProject1's build.gradle otherwise, even if the project itself would compile fine, the IDE wouldn't recognize the types included in the AAR library. Note that the ./ in the path also seems to be important, without it the IDE still doesn't recognized the types.
I faced to the same issue, and I figure out it by putting all libraries on that depends LibraryProject1 in LibraryProject1/libs as a .jar.
I think that aar library cannot be linked to another aar library.
Hope that help you,
Best regards

How to Import Github non Android Studio Project as library into Android Studio?

I am trying to import standout library which is a github project as library in my project.What i tried is below:
created a folder in my root project directory named 'libs'
copied the complete folder 'library' of the Standout project on git into 'libs'
renamed the folder 'library' that i just copied to e.g. "standout" (just to avoid confusion)
now added this library in my settings.gradle with the following command:
include ':libs:standout'
going to my build.gradle file of my AppProject and added the following line to my 'dependencies':
compile project(':libs:standout')
but i got error and then added like this
compile fileTree(dir: 'libs', include: ['standout'])
gradle sync was successful but there is red mark on the src files of the library project..I couldn't access the library src files from MainActivity of my Project.As the github project wasn't the android studio project do i need to do anything extra for that?
I have tried below way suggested by Wesley:
Download or clone the git repository, copy the library folder into
your project root folder.
Then in your project settings.gradle file, add a ':library' at the
end of the include line, like this: include ':app', ':library', then
gradle sync your whole project.
At the end, in your app module or you own application module, edit
the build.gradle file, add a line in your dependencies:
compile project(':library')
BTW, you can change the folder name ("library" in this case) to any
name you want (like "standout-library" if you want) when copy it into
you project's root folder, then, when you edit the gradle files, just
use the changed name.
But got the below error:
Error:Configuration with name 'default' not found.
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.mapandmap.standout"
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 project(':standout')
compile 'com.android.support:appcompat-v7:22.1.1'
}
My settings.gradle:
include ':app',':standout'
screenshot of my Project Tree:
You need to resolve R in each file of "standout" library which is showing as red now.
You can simply add by doing this. Go to Android Studio File->Project Structure-> + , You will get four options to add a new module. From there choose "Import Existing Project"->Next-> browse to the directory you have downloaded library and choose "library" directory and then "Finish".Android Studio will take some time to sync library to your project. Finally add dependency in settings. I just tested by adding this library in a project and its working perfectly.
You could move the library to your main "app" project but its better to add as dependency.
I followed the answer of sbr1308 but I have to do some more things.What you have to do:
Go to Android Studio File->Project Structure-> + , You will get four options to add a new module. From there choose "Import Existing Project"->Next-> browse to the directory you have downloaded library and choose "library" directory and then "Finish"
If there is any error in the classes of the library then Go to File->Invalidate Caches/Restart->Invalidate and Restart.It will take time to indexing.
You have to add the dependency in the app's build.gradle
compile project(':standOut') and then sync.

Resources