When I try using using the dependency implementation 'com.github.dhaval2404:imagepicker:2.1' or implementation 'com.github.dhaval2404:imagepicker-support:1.7.1' I will get a warning message that says "Failed to resolve: com.github.dhaval2404:imagepicker-support:1.7.1
Show in Project Structure dialog</ a >
Affected Modules: app</ a >"
How do I get rid of this warning?
This is the link to the github I am working on https://github.com/Dhaval2404/ImagePicker
I tried adding the build.gradle from the folder but I don't know where to add it, when I copy and paste the entire thing I get an error saying
"Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'app\build.gradle'"
go to the Gradle Scripts folder and click settings.gradle. Copy and paste maven { url "https://jitpack.io" } in the repositories{}. Now you can go back to build.gradle in your Gradle Scripts folder to add in your implementations.
Related
While learning android studio from udacity they asked me to download a project; I did so but while I was importing it to android studio I got an error message:
The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3.
Why did I get this error?
If you did not figure this out yet, I am just starting the same project too. I changed the classpath like above. I then found a website to use the latest version of gradle and the plugin. It says "You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file." I did the first one.
Then, I got errors for both build.gradle files in the project and app version. I get this error: Could not find com.android.tools.build:gradle:7.0.3
If you get this error, click the link "Add google Maven repository and sync project". Then you have to click "Do refactor".
Now you come across another error in one of the build.grade files. This stackoverflow link will tell you: Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
Finally, replace testCompile with testImplementation and then you should get BUILD SUCCESSFUL.
The project's Gradle version you're trying to clone is outdated. Change it based on your android studio version.
on your build.gradle(Project) change the version and sync
classpath "com.android.tools.build:gradle:4.1.2"
Got the solution :)
In gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
In build.gradle project level:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In build.gradle module level:
Replace all "compile" with "Implementation" and do other suggested version updated and you are done here :)
Hope this works for you, if yes just press that up button :)
If not getting any solution, the best you can do is copy the "app" folder of your project(using file explorer) and paste it in a newly created project(should be of same name as of your project), in that way you'll get already synced gradle and newly created version of your app.
Because, every important thing in your project is present in its app folder and when you create a new project with same name and copy app folder from your older version of your project, you will have a newer version of your project with all same resources.
Note: You can't move through branches and other commits
I saw this issue several times with Android studio. Below trick worked me the best.
Android Studio suggests to upgrade to newer version, please upgrade it and let it sync
Mostly you would see error message again
Now, Go to File -> Invalidate Caches/Restart
It should work now
If it shows same error then I don't know what to do.
If it shows different error then repeat from step 1 to 3 for new error.
Hope, it helps some..
This library contains 1 bug.
It was fixed here: https://github.com/heinrichreimer/material-intro/pull/287
What is the simplest way to implement this fixed version of the library to my Android studio project? I'm new to using libraries from GitHub, I'd appreciate some help on this.
I'm currently using this: implementation 'com.heinrichreimersoftware:material-intro:2.0.0'
You have several options:
Wait for/Ask the owner to release a new version and use it.
Fork the project and release one version of your own.
Download the library and import it in your project as a dependency.
I'll explain here the third option:
Go to https://github.com/heinrichreimer/material-intro.
Click the Code button and Download ZIP.
Open the ZIP file and open the material-intro-master folder.
Rename the library folder to material-intro-library.
Open your project in Android Studio.
Go to File > New > Import module... and select the material-intro-library folder.
Finally, open your build.gradle file and replace implementation 'com.heinrichreimersoftware:material-intro:2.0.0' with implementation project(path: ':material-intro-library')
You could use JitPack.io which acts as a repository for libraries just like maven and also to compile any Android or Java library using Gradle on GitHub at the required commit (found in the the pull request) and use the compiled library in your project in two steps. No need for waiting, cloning, importing or even compiling on your local PC, all done and covered by JitPack.io. Here are the the steps (retrieved from website):
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.heinrichreimer:material-intro:b35d1c9d65'
}
You can clone material-intro library to your pc. Place the material-intro/lib folder to your project root directory path.
add include ':library' to your setings.gradl
add implementation project(':library') to your app-level build.gradle
You could use JitPack.io which acts as a repository for libraries just like maven and also to compile any Android or Java library using Gradle on GitHub at the required commit.
Step 1. Add the JitPack repository to your build file
Step 2. Add the dependency
I have a gradle project that is currently working fine. I now need to add a Java library (packaged as Jar) as a dependency and use classes defined in the Jar file. This works fine if I use flatDir as a repository in build.gradle,
repositories {
mavenCentral()
flatDir {
dirs '../java_library/build/libs'
}
}
and then in the dependencies,
compile name: "java_library-0.0.1"
I can then easily import classes from the library into my own code, build is successful, everything works.
However I cannot do this on our build server so instead of referencing the jar from my local workspace, I need to fetch it from our organization's internal maven repository.
maven {
url 'http://customer_repo:0000/maven'
}
and then in dependencies,
compile ('our.company.groupid:java_library:0.0.1')
I have verified that the library is published to the local repository and that gradle does not say it was not able to fetch the dependency (it was giving one such error before the Jar was published to local repository).
But now when I build the project it given compile errors saying it did not find the symbol pointing to the class imported from the Jar library. The same error is shown in IDE (IntelliJ) which was also working fine with flatDir.
Is there anything obvious that I'm missing?
SOLVED:
Yes there was one obvious thing that I was missing. In the JAR library project, build.gradle had the following,
publishing {
...
publications {
artifactId = 'java_library'
}
}
I was missing
from components.java
as soon as I added it,
publishing {
...
publications {
artifactId = 'java_library'
from components.java
}
}
and published the library again I was able to import it successfully in the other project.
url 'http://customer_repo:0000/maven'
First, open this URL in browser and ensure you can reach you library by clicking links (i.e. our -> company -> groupid -> java_library -> 0.0.1)
Second, download library and check it really includes missing class file. Probably, you uploaded wrong file which is not library.
I will have the following setup:
MyRootProj
|
---- MyJavaProj1
|
---- MyJavaProj2
|
---- MyWebProj
I want to do the development on Eclipse and have installed BuildShip plugin.
From this discussion it seems that its not possible to create a multi-project setup in Eclipse for Gradle.
I tried the following steps:
I created a directory MyRootProj and inside that ran:
gradle init
This created the default files.
Then I modified the build.xml of MyRootProj to:
plugins {
id 'eclipse'
}
allprojects {
repositories {
mavenCentral()
}
apply plugin : 'eclipse-wtp'
apply plugin : 'java'
}
Till this point everything is fine.
Now following the steps in above link, I create MyJavaProj1 directory under MyRootProj and add a blank build.gradle inside it.
I then modify the settings.gradle file of MyRootProj to:
rootProject.name = 'MyRootProj'
include 'MyJavaProj1'
And then did a gradle refresh on the root project as recommended.
This creates the MyJavaProj1 with all the files. However, this does not have a Gradle recommended package structure for java projects already.
When I right click on eclipse project explorer and do a New -> Gradle Project, the project which gets created comes with src-main-java, src-main-test, etc. structure out of the box.
Why does that not happen with the way I am creating MyJavaProj1 above?
Long story short, I have created the root project. Now I want to create sub projects. However, I want to do it in Eclipse and I want the sub-projects to have autocreated Gradle recommended structure for Java Projects.
Disclaimer: I'm very new to Gradle and Dependency Management. I tried reading the documentation but just couldn't get through the sheer amount of information. I also couldn't find anything useful to answer my question, so sorry if this has been answered before, I tried searching...
So my situation is as follows: I have one Java project that's supposed to give me a standardized way of using program configurations using JSON files. This project has a dependency on Gson. So far so good, I simply added compile 'com.google.code.gson:gson:2.6.2' to that projects dependencies and all's fine, the library shows up as External Library in Idea, and I can use it and stuff.
Now I want to use that project in other projects to make use of the configuration stuff. And I can not for the life of me figure out how to add the project or the library jar to other projects using Gradle.
I tried things like copying the library jar to the libs folder of the projects to use it in and adding compile files('./libs/myLibrary-0.0.1.jar') to the dependencies list, or adding the jar as a library via the Project Structure thing in Idea. None of these methods worked, and I'm at my wits end.
Any help would be appreciated.
If you or your company have a central binary repository, such as artifactory. Then you should set up publishing your jar there.
But since you haven't mentioned a central repository, I'll assume that you don't have one, and are simply trying to get your dependency to work on a single machine. In that case, what I suggest doing is this:
Add the maven-publish plugin to your dependency project:
apply plugin: 'maven-publish'
Also make sure that you define the group, version and name variables of your project (see here). You'll need them later. Then add a publishing definition that will tell maven-publish to publish all classes:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
Using these settings you should now be able to run the publishToMavenLocal task. Do it. If successful, the dependency jar should now be in your local maven repository (~/.m2/repository)
Now, add mavenLocal as a repository in the project that needs the dependency:
repositories {
mavenLocal()
}
(you might want to add additional repositories here, such as mavenCentral())
Also add your jar's group, name, and version just like your gson dependency:
compile 'yourgrou:yourname:yourversion.
Gradle should now be able to fetch the dependency from the local maven repo.
You have couple of options. First and easy is to build your base project and available in your local maven repository and use it. To make your project available is your local maven repo, use maven plugin. In your build.gradle file, add the following.
apply plugin: 'maven'
Now use gradle clean build install to publish the jar to your local repo. Remember that install task is the one actually put your jar into your local.Then head over to your other project which depends on this one and tell it to look into your local maven repo by adding mavenLocal to the repositories.
repositories {
mavenCentral()
mavenLocal()
}
Another option is, if you are using centralized repo in your company, you can publish your base jar and use it in the other project. Check out the documentation.