So I've tried adding Firebase dependency to my gradle project. But it doesn't seem to be working. It adds fine, there's no errors or anything and I can see the firebase jar in my Referenced Libraries. But whenever I try to import anything from it like import google.com.firebase, it doesn't show up. What am I doing wrong? These are the only imports I'm seeing.
This is my repositories thing in build.gradle
repositories {
mavenCentral()
google()
jcenter()
}
This is my dependencies thing
dependencies {
compile 'com.google.firebase:firebase-database:19.3.1'
}
So basically, the dependency adds correctly I think, it does show up on the Referenced libraries on my IDE but I don't know why I cannot access it?
Btw I'm not making an Android app, it's a mod for minecraft that uses forge gradle.
Also this is my gradle version: https://services.gradle.org/distributions/gradle-4.1-all.zip
It was because i used an dependency meant for android developers with the aar extensions so instead of using
compile 'com.google.firebase:firebase-database:19.3.1'
In dependencies in build.gradle using this which is meant for the java thing works now.
compile 'com.google.firebase:firebase-admin:6.16.0'
Related
It's probably very simple, but only to people who know what they are doing.
I have a Java program that imports these two:
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
As an aside, I don't want to use the lang3 package but the lang package.
I do not have anything in my Gradle file about these. When I try to build the file, it gives me errors for these two, saying the packages do not exist.
My questions are:
Do I need to add them as "compile" or as "api"?
What is the exact syntax? I have lines that look like this:
api group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
How do I find the right name (or should I just invent one)? and the version?
Anything your code needs (besides basic JRE classes) is a dependency for your code. Gradle manages these dependencies, usually downloading them from a repository.
First you need to find such a repository. You probably have repositories already configured in your build.gradle, like so:
buildscript {
repositories {
mavenCentral()
// maybe more repositories
}
}
That means Gradle will try to download dependencies from Maven Central. You can either do a web search for "gradle" and your dependency, or go to repository and search, or check the dependency's homepage.
You'll end up with a dependency name and version like 'org.apache.commons:commons-lang3:3.12.0'. This needs to go in your build.gradle.
Gradle has different dependencies:
buildscript dependencies provide code that Gradle needs to execute to build your project, e.g., a tool to pull in version control system information or generate code
implementation dependencies are dependencies your code needs to run, like a logging framework or JSON parser or PDF generator
test dependencies are dependencies needed to run your automated tests, like JUnit
Depending on where you need the dependency, you put it in the buildscript or the dependencies block.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.tmatesoft.svnkit:svnkit:1.9.+'
}
}
dependencies {
implementation 'pdfbox:pdfbox:0.7.3'
testImplementation 'junit:junit:4.+'
}
You don't need to repeat the implementation dependencies for the testImplementation btw, as it inherits them automatically.
You can define your own configurations as need; see the Gradle manual on dependencies, for example if you have different test suites (unit, integration, performance, ...) that need different dependencies.
you'll have to go to their official website and get the implementations then add those to the dependencies(you'll find it at the bottom of the file) in the build.gradle(module) it would look something like -
the $lifecycle_version might be somethiing like 1.2.3 or some version number.
this is what I got (not exactly sure if this is right)-
implementation 'org.apache.commons:commons-lang3:3.12.0'
got from library website in the gradle short tab
in the build.gradle(project), look for maven repo.
Once done, you'll be able to import the respective libraries.
I have an AlertDialogue object called dialog. I am attempting to add an icon to it. I see that this syntax is now deprecated:
dialog.setIcon(getResources().getDrawable(R.drawable.myImage);
I'm reading everywhere that this should work:
dialog.setIcon(ContextCompat.getDrawable(context, R.drawable.myImage));
However, the ContextCompat syntax is not being recognized by Android Studio. Is there something that I should be importing? Thank you.
***Update: Thank's to #Sharj for the correct answer below. I made a quick video too if you guys need a visual: https://www.youtube.com/watch?v=eFiaO0srQro&feature=youtu.be
ContextCompat is part of support library v4. Have you added support library 4 to your project?
android.support.v4.content.ContextCompat
You can include support library to your build.gradle file under app folder if you haven't already
dependencies {
// other stuff here
compile 'com.android.support:support-v4:23.0.0'
// update the 23.0.0 to latest version available
}
androidx.core.content.ContextCompat
from AndroidX dependency
implementation 'androidx.appcompat:appcompat:1.1.0'
I had the same issue and this and a few more posts helped me.
With Android studio you have multiple Gradle files.
I got my code to work by adding the dependencies section into Gradle (Module : Library) or the file that has "android {" ...
dependencies {
// other stuff here
compile 'com.android.support:support-v4:23.+'
// update the 23.0.0 to latest version available
}
If you are using Android gradle plugin 3.0.1, add google() to your allProjects repositories in the build.gradle file (project level) then sync
like this:
allprojects {
repositories {
google()
....
//other repos
}
}
Adding this to build.gradle(Module:App) under dependencies resolved the problem
compile 'com.android.support:support-v4:23.0.0'
I am having a problem with Android Studio recognizing classes inside an #aar library imported locally.
So... I've made a library and exported is an aar file. Inside android studio I selected Import Module and them Import .JAR or .AAR Package.
The project compiles and works with the classes inside the aar file but Android studio can not find the classes or offer any auto completion of so all.
Here is a few of screenshots:
The same problem also happens with other #aar libraries imported the same way:
Any suggestions?
Edit:
build.gradle:
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':UpPlatformSdk')
compile project(':simpleorm')
... // more libraries here
}
settings.gradle:
include ':app', ':UpPlatformSdk', ':wear', ':simpleorm'
Looks like you could do this How to manually include external aar package using new Gradle Android Build System
If you have them in your lib folder
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'UpPlatformSdk', ext:'aar')
}
This may not be the quickest way, but this works for autocompletion and also solved my problem of missing classes when I tried compiling my local AAR using the method #puj described. Essentially you need to create a local Maven repository to host the AAR, but any changes you make are pulled by the build system when you do a Gradle sync.
Android Library AAR depending on another library
Google promotes their new Java Client library here: https://developers.google.com/appengine/docs/java/googlecloudstorageclient/
Note: I am not talking about the native REST library. I want to work with the Java Client Library.
On the website, Google does not specify the import directive for Gradle. For Maven, pom.xml looks like this:
<dependency>
<groupId>com.google.appengine.tools</groupId>
<artifactId>appengine-gcs-client</artifactId>
<version>RELEASE</version>
</dependency>
When I change this to work with my Gradle project, it doesn't work:
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:RELEASE'
}
It finds the tools there, but the com.google.appengine.tools.cloudstorage cannot be resolved (it resolves tools, though).
What I did then: I removed the library and seached for "gcs" in the Android Studio dependencies dialog; and it finds and adds the following directive to build.gradle:
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:0.3.9#jar'
}
Same problem with that as before: tools is resolved, but not tools.cloudstorage.
What am I doing wrong? Where does the library live/which import statement will I need to add to Gradle?
I don't want to download the jar as I want my project to update jars automatically. mavenCentral() is set, and here is my full build.gradle file, just in case you need it:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.appengine.tools:appengine-gcs-client:0.3.9#jar'
compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
}
Any help appreciated, thanks!
You can use the following to specify version 0.4.4 (the most recent as of 1/14/2015):
compile 'com.google.appengine.tools:appengine-gcs-client:0.4.4'
or specify the latest version with a plus sign:
compile 'com.google.appengine.tools:appengine-gcs-client:+'
Using the latter is the faster answer, but it may cause unintended compatibility issues in the future as updates are release.
I have imported one project into Android Studio but I got the error:
Could not find com.android.support:support-v4:19.1.0.
Where could I find this file? I have imported the project using Gradle.
I have the Android Studio version 0.5.7 the last android sdk and java 1.7u55.
Just add this code to you build.gradle file
dependencies {
compile 'com.android.support:support-v4:19.+'
}
and press Tools -> Android -> Sync Project with Gradle Files
Gradle will download necessary files by himself
It does not work for me either. It works with 19.0.1
But if (I use gradle) I do this in my build.gradle:
repositories {
def androidHome = System.getenv("ANDROID_HOME")
mavenCentral()
maven {
url "$androidHome/extras/android/m2repository/"
}
}
It finds the artifact.
From the SDK Manager, delete and re-install the Android Support Library 19.1 package.
I had this same problem with morning. I found the Jar file that I needed in /<MySdkFolder>/extras/android/support/ - in there are some sub folders with the different support libraries in them, so the last part of the path depends on which one that you want to use.
I just copied this into the lib folder of the project. I'm sure there is a more technical solution but it worked for me.
Following theory works at me:
Android Studio has problems importing support-v4:19.1.+ library when it comes through a transitive dependency.
Solution Adding support-v4 as own dependency and exclude this lib where it comes transitive. then i could not more see this import issue
Right clicking on the library and select the import as library option from the context menu works for me.
Try to go
Project Structure -> Dependencies -> Add : then select -> File
dependecies
then select the proper library
This artifact is available on google maven repository. So need to add following in the build.gradle:
allprojects {
repositories {
mavenLocal()
google()
}
}
I had a similar problem. This line to build.gradle works -->
implementation 'com.android.support:support v4:28.0.0'