i created a fresh project in the Android studio and i would like to add this logging plugin.
https://github.com/orhanobut/logger
So i copied all into ProjectDirectory/app/build.gradle go get something like this.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.orhanobut:logger:1.11'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
}
But after the rebuild process Android studio is still import wrong class:
import java.util.logging.Logger;
So i think, that dependency was not imported correctly.
How can i do it it the right way please?
Well it worked in mine just fine,type Logger. and it will give a suggestion window with 2 types of logger like it always does when multiple import types are available and select the one which belong to your lib.
The line 'com.orhanobut:logger:1.11' assumes that you have declared a repository that hosts the artifact it identifies.
If you have declared a valid repository, you've most likely been tricked by auto-import. Remove the import and be sure to select the proper logger import when prompted.
If gradle build completed successfully without errors, then the import was completed correctly. However in your java classess, if you have 2 libraries with the same name (as in your case, there is 2 logger libraries) you can type logger then press ctrl + space to open a menu that lets you choose which logger library to use.
Related
I'm working on an assignment for an online course on Udacity. The starter code can be found here.
The only thing I've done to the starter code was to add a new Activity with New > Activity > Basic Activity. I then got import errors in the two lines
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
Specifically, I get a Cannot resolve symbol 'FloatingActionButton' and same for Snackbar.
I've spent the past hour here (was having another problem before this one, also with import statements but in the MainActivity), and have tried the following:
Changing the appcompat on build.gradle file
File > Invalidate caches / restart
Build > Rebuild project
Sync project with Gradle files
Re-installing Android Studio
None of this worked.
The build.gradle file is
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
}
I'm not really sure what started the error(s) to begin with since it's been a complete rabbit whole but I think it was after doing some update to Android Studio.
Can anyone please point me to the solution?
While adding dependencies, just use the same dependency version (which is available on local machine) across similar dependency packages so use
compile 'com.android.support:design:23.4.0'
instead of
compile 'com.android.support:design:23.3.0'
Note : I also recommend to work with latest dependencies and android studio which improved and thus more helpful (there's been some great improvement in latest android studio IDE to handle build errors)
I'm trying to import this as a library in a project I'm working on in Android Studio:
https://github.com/d4rken/myolib
I cant workout exactly how to do it. even before I try to do this, I tried to open the project using new->Import project-> (selecting the settings.gradle). This then complained about not knowing about:
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
So I tried adding these manually using the advice on:
Importing github projects as library to existing project
Adding external library in Android studio
But its still complaining about no cached version for offline mode. If I do disable work in offline mode then, well it just sits there forever. I want to give it everything manually because in my experience disabling work in offine mode usually doesn't help.
I completely understand this isn't a new topic on Stackoverflow. The issue of how best to import libraries as .jar, .aar, .os etc. etc has been covered a few times. And yet most answers are subtly different and some work sometimes, others work other times.
Does anyone know of a detailed explanation about how I should achieve this ?
If anyone has been successful in importing this project and using its libraries I will be eternally grateful if you could tell me how you achieved such wizardry.
You import the library through your app's build.gradle file. An import section looks something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:24.1.1'
compile "com.android.support:support-v13:24.1.1"
}
So to import the library you just linked, you would simply add this line to your dependencies section, as per the readme:
compile 'eu.darken.myolib:myolib:0.0.4'
I'm trying to migrate an Android project developed with Eclipse ADT to Android Studio. I've already read the instructions mentioned here http://developer.android.com/sdk/installing/migrate.html and it works fine!
Gradle builds a new android project but I need to "hardcode"(modify manually) the gradle.build file in order to make the libraries work properly. All the other stuffs work fine.
This is the ADT project
MyApplication/
-->assets/
-->libs/
---->android-support-v7-appcompat.jar
---->android-support-design.jar
-->res/
-->src/
-->AndroidManifest.xml
-->project.properties
The first library is automatically recognized by Gradle, and it is substituted with
compile 'com.android.support:appcompat-v7:23.2.1'
in the grandle.build file.
Instead the "android-support-design.jar" is not recognized and it is added to the gradle.build as
compile file('libs/android-support-design.jar')
but it is not working at all.
At the moment, I need to manually substitute the
compile file('libs/android-support-design.jar')
with
compile 'com.android.support:design:23.2.1'
In order to make the build work effectively.
Is there any way to force Gradle to recognize that library and automatically import it? Can I download a version of that library that is recognized, anywhere? At the moment I'm taking both libraries from
<sdk>/extras/android/support/
Thank you all.
I need to "hardcode" the gradle.build file in order to make the libraries work properly
I'm not sure what you mean by "recognize" and "hardcode", but if you just have jar files that you can't use the compile line like for the support libraries, then you can use this line, which will take any jar file in the libs/ folder and compile it. You don't need to hard-code any of those.
compile fileTree(dir: 'libs', include: ['*.jar'])
Otherwise, you should already have these.
compile "com.android.support:appcompat-v7:23.2.1"
compile "com.android.support:design:23.2.1"
But, if you want to get fancy with Gradle, you can do something like this to keep all the support libraries the same version.
ext {
supportLibVersion = '23.2.1' // variable that can be referenced to keep support libs consistent
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
I'm using the gradle build script, in android studio to fetch the Parse android SDK, as follow:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.parse.bolts:bolts-android:1.+'
}
The build process succeeds with no errors, yet , when I the to import com.parse.Parse; I get cannot resolve symbol parse.
To my understanding, that build script was supposed to download the Parse SDK from a maven repository, and build it, or otherwise to fail.
Where do I have wrong?
Check Parse's Android Studio guide again, you'll see this:
Step 1 instructs you to download the SDK.
Step 2 asks you to first put Parse-*.java to the project's libs folder, and then add the script you've shown in your question into build.gradle. Notice that the library pulled from maven is just an auxiliary library, not the Parse library itself. This is why Android Studio cannot find the Parse class.
I'm trying to add a Leader Board to a Chrome cast project and am getting errors. Android project in Android Studio. In my gradle build - Error: more than one library with package name 'com.google.android.gms'
I understand why you don't want to use two different libraries with the same name, but not sure how to use the same library throughout the project. Here are the two uses of gms:
1) Main activity has dependency on 'CastCompanionLibrary-android-master' which then uses google-play-services_lib. I'm not sure which version of gms this uses, but the version number is referenced in the manifest. Is this just grabbing the version # of play services that they have installed on their phone?
2) BaseGameUtils - has dependency on com.google.android.gms:play-services:+ (I think this is grabbing the most recent version of play-services, but doesn't match the other one.
MainActivity gradle file
dependencies {
compile project(':BaseGameUtils')
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':CastCompanionLibrary-android-master')
}
CastCompanionLibrary-android-master dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':android-support-v7-appcompat')
compile project(':android-support-v7-mediarouter')
compile project(':google-play-services_lib')
}
BaseGameUtils dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:+'
}
So, the problem (I think) is these two versions of com.google.android.gms, but how do I rectify it so that they all use the same version. I've had almost 2 years of working with Android, but this is my first question on stack overflow. Help is appreciated - Is there a guru out there that has the answer to this?
Seems like you have modified the gradle file for CCL since what you have there does not match with what CCL has in GitHub. The best approach is to only use the piece of play services that you need; for example CCL only needs the play-services-cast (besides the base, which will be pulled in automatically) so if you follow that pattern, things would look smaller (less possibility of running into the 64K dex limit) and less collisions.CCL, in Github, lists its dependency as:
compile 'com.google.android.gms:play-services-cast:6.5+' so you might want to start using versions and also follow the recomendation I just made (same applies for any other code that you have and uses play services; just pull in what you really need)