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
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..
At our company, we use Artifactory to manage artifacts and dependencies of Gradle.
We have library that was build with Gradle 6.0.1, in addition, have a micro-service that was built with Gradle 6.0.1 that is using this library as a dependency.
I verified that this library exists in the declared repo.
When we try to build the project we get an error that this library doesn't exist in the declared repositories and that we should declare the correct one.
The weird part is that if we downgrade the micro-service to Gradle version 5.6.2 the library does get download and working.
We also tested it with other older micro-services that we have based on a template project that is built with Gradle version 4.10.3 and It's also working in them.
What could be the issue?
The library I was referring to in my question didn't have the POM file published with it.
So either I will need to publish it again with the POM being generated (since the library itself was built with Gradle and not Maven - there is a way to generate POM with Gradle)
or:
I will add the following code to build.gradle file so Gradle will download the artifact even though it doesn't have POM file.
repositories {
maven {
url uri('lib')
metadataSources {
artifact()
}
}
}
What is the exact dependency I need to develop a Gradle Plugin in Java? Ideally I would like to get it from a well-known repository such as Maven Central or similar.
I have a Maven project with a core functionality and I just added two extra plugins, one for Ant, one for Maven. They are already tested and working; easy! Now, I wanted to add a third module for a Gradle plugin to make this functionality also available from any Gradle project.
However, I can't find the exact dependencies I need to develop a Gradle plugin.
The Gradle docs (such as https://docs.gradle.org/current/userguide/java_gradle_plugin.html) are not very well written to say the least. They mention:
the gradleAPI() dependency
or the java-gradle-plugin dependency
But they are quite unclear... no group, no version (really?).
If anyone can enlighten me to where I can get these dependencies from, I would be very thankful.
Gradle's public and internal APIs, aka gradleApi(), are bundled with the Gradle distribution and not independently published and therefore not easily consumable by Maven builds. There's the pending epic #1156 (Ensure plugin cross-version compatibility by allowing a user to depend on gradlePublicApi()) that might help here.
Since Gradle plugins are best to be built with Gradle, a pragmatic solution is to invoke the Gradle build from Maven and attach the produced artifact to the Maven build. Andres Almiray (aalmiray) once described this in the blog post Running Gradle Inside Maven (Web Archive Link). He describes the following high level steps:
Create a new Maven module (e.g. gradle-plugin) and add attach it to the parent POM
In the POM of gradle-plugin add a dependency to your core module. Use the maven-dependency-plugin to store dependencies to the Maven build folder, e.g. target/dependencies.
Create the build.gradle, add a Maven repository that points to target/dependencies (step 2) and let it depend on the core module as well as gradleApi(). Implement the Gradle plugin.
Use the exec-maven-plugin to invoke the Gradle build.
Use the maven-resources-plugin to copy the Gradle built plugin jars to the standard Maven build folder.
Use the build-helper-maven-plugin to attach the copied jars to the Maven build.
Sample project to be found here (gradle-in-maven).
https://docs.gradle.org/current/userguide/custom_plugins.html#sec:custom_plugins_standalone_project
In here it is mentioned that it is gradleApi() and I know that this works (from experience). The localGroovy() on that page is only needed if your plugin code uses groovy (does not apply if you only use groovy in the build.gradle of your plugin).
java-gradle-plugin is a library that makes it a bit simpler to make plugins, it is not required though. I personally prefer using gradleApi only.
EDIT:
It appears I've misunderstood the question. Here are the steps to get gradleApi jar:
Create a Gradle project with your desired Gradle version.
Add implementation gradleApi() dependency.
Import/run the project once.
Go to your .gradle folder (located in home folder in Linux-based operating systems).
Open caches folder
Open the version folder you want, e.g. 6.0.1
Open generated-gradle-jars folder.
Copy the jar to wherever you want and use it.
For me the 6.0.1 jar is at ~/.gradle/caches/6.0.1/generated-gradle-jars/gradle-api-6.0.1.jar
Please note that I have not tested this, I know the jar is there but I haven't tried using it.
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.
I am trying to import common-math library to my Android Studio project. I placed the file commons-math3-3.6.1.jar file in libs folder and in the gradle file I have this line:
compile 'commons-math3-3.6.1.jar'
But I get this error: `
Error:(32, 0) Supplied String module notation
'commons-math3-3.6.1.jar' is invalid. Example notations:
'org.gradle:gradle-core:2.2',
'org.mockito:mockito-core:1.9.5:javadoc'.
Can anyone tell me what I have to do?
Is there a reason you need to use the jar file? You can get the file directly from Maven repository using something like this:
compile 'org.apache.commons:commons-math3:3.6.1'
Available on both JCenter and MavenCentral.
in Android view open Gradle Scripts - build.gradle and add this to dependencies:
implementation 'org.apache.commons:commons-math3:3.6.1'
You can also check their websites if newer version isn't available list of latest versions