As a beginner Android Dev I often faced this error in multiple old projects. The code for including a dependency is:
implementation 'com.example.library'
or for kotlin
implementation("com.example.library")
The error logs look somewhat like this:
> Could not find com.example.library
Searched in the following locations:
https://repo.maven.apache.org/maven2/com/example/library
https://repo.maven.apache.org/maven2/com/example/library
https://jcenter.bintray.com/example/library
https://jcenter.bintray.com/example/library
https://jitpack.io/com/example/library
https://jitpack.io/com/example/library
https://dl.google.com/dl/android/maven2/com/example/library
https://dl.google.com/dl/android/maven2/com/example/library
This often means that the library is either not available on provided repository or repositories are not added properly.
Reproduction Steps:
Create a new android project with gradle
Add this line to build.gradle (app):
implementation 'com.arthenica:ffmpeg-kit-min:6.0-1'
Sync
Failed to resolve: com.arthenica:ffmpeg-kit-min:6.0-1
There are multiple solutions to this problem. Before proceeding:
google()
mavenCentral()
gradlePluginPortal()
Getting into the fixes:
- Using Jitpack.io or other repositories:
You can simply go to jitpack.io, and paste the library name from github into the search bar, in this case:
example/library
Then you need to add this to your settings.gradle or add the repositories inside build.gradle (Project)
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Inside build.gradle(app), in dependancies you may paste this. The exact link will also be provided if you scroll down the jitpack site:
implementation 'com.github.example:library:version'
Now Sync. These instructions are also provided in the jitpack website right below and it also tells you if the library is actually available on jitpack.
- Using alternative repository:
Some of the older librbaries were hosted on the Jcenter repository which has been now sunset and many libraries cannot be downloaded. This has caused many apps to not build. For this you may include this repository in repositories (Depending on gradle version in settings.gradle or build.gradle (Project)):
maven { url "https://maven.aliyun.com/repository/jcenter" }
Now sync.
Maven Aliyun is a set of mirror repositories maintained by Alibaba for Chinese developers. It also includes other repositories such as google, spring. Developers from outside china can also access this repository.
- Manually include the aar of the library:
This is the most reliable solution. You can clone the library or download it. Open a command line in the root project of library and then run this command:
gradlew clean :library:assembleRelease
Replace 'library' with the name of the libary name in the folder. It is often named 'library'. Potential issues you will face during this are:
sdk.dir=D:/Example/Android/Sdk:library:compileReleaseJavaWithJavac failed. For this you will need to edit the gradle.properties to add this code:
org.gradle.java.home=C:/Program Files/Java/jdkxyz This jdk should be compatible with the project.Once build is successful, navigate to: \library\build\outputs\aar and copy the library-release.aar file.
Navigate to your android project. Paste aar file to app/libs. If this folder does not exist then create a new libs folder inside app folder.
Inside repositories add this line of code
flatDir {
dirs 'libs'
}
And inside the dependancies now you can simply add this code to include library:
implementation files('libs/library-release.aar')
Sync the project and use the library.
- Adding the complete library in Android Project:
This is very reliable and useful because you can make changes to the code of the library as you see fit. Download or clone the libary project from github. You can then simply copy the 'library' folder from the root project and paste it inside your Android Projet. Inside settings.gradle:
include ':library'
Inside build.gradle (app):
implementation project(':library')
Now sync and you will be able to use the library as you like.
Example
Create a new android project with gradle
Add this line to build.gradle (app):
implementation 'com.arthenica:ffmpeg-kit-min:6.0-1'
Failed to resolve: com.arthenica:ffmpeg-kit-min:6.0-1
Solution
Follow solution number 3 to generate an aar and add it to the project.