preface
Gradle has released a 7.0 version of its own dependency library. Most of the tutorials I searched on the Internet are before 7.0. Although there are also 7.0 articles, I have met some problems. At the time of writing this article, I haven’t published it yet. Anyway, document the process and problems first. Three days later, finally solved all the problems, but some problems forgot to record, also do not remember, should be a small problem, Baidu can solve, otherwise I will not forget. I hope I can give you a little help.
Set up process
1. Create Android Library
Create an Android Project and then add an Android Module. Select Android Library when creating the Module. Then write your own code in the Module.
2. Add the configuration
Add the following configuration to the build.gradle file in the Module
plugins {
...
id 'com.android.library'
id 'maven-publish'
}
android {
...
}
afterEvaluate {
publishing {
publications {
release(MavenPublication){
from components.release
groupId = 'com.github.xxx'
artifactId = 'release'
version = '1.0.0'}}}}Copy the code
3. Upload a lot
To create your local Git repository, use the command line to go to your project’s root directory, type Git init, and press Enter. Go back to AS and you’ll find a Git option on the menu bar. Git -> Github -> Share Project on Github -> Git -> Share Project on Github
4. Create a Tag and release it on Github
Select the node you want to publish to create a Tag, usually named version number, and push it to Github. Next up on Github
Select the tag you just pushed, fill in the Publish Release name, and click Publish Release
5. ToJitPackpackaging
Log on to making
The dot corresponds to the Got it after the TAG
6. Start using
The pit of tread
1. Java11
* What went wrong: An exception occurred applying plugin request [id: 'com.android.application'] > Failed to apply plugin 'com.android.internal.application'. > Android Gradle plugin requires You are currently using Java 1.8. You can try some of the following options: - changing the IDE settings. - changing the JAVA_HOME environment variable. - changing `org.gradle.java.home` in `gradle.properties`.Copy the code
When building with Gradle7.0, you need JDK11 to run. This is easy to solve, modify Module build.gradle file
compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } kotlinOptions { jvmTarget ='11'
}
Copy the code
Then you have to add a jitpack.yml file to the root directory
Before_install: -sdk install 11.0.7.hs-adpt - SDK use 11.0.7.hs-adpt JDK: -openjdk11Copy the code
Submitted to the JitPack package, ugh, ugh, and an error? I checked the log
I didn’t cut it. I still used the 1.8, but I realized it was cut the next day, and I was black. It turns out that you can select JVM versions on the JitCi and I recommend it
2. allowInsecureProtocol
* What went wrong: A problem occurred configuring root project 'app'. > Could not resolve all dependencies for configuration ':classpath'. > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'cache(http://cache)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.0.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifa cts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.Copy the code
This means that my project uses an unsafe http://cache, like maven’s cache, but I can’t find it. It just keeps getting stuck. I had to change the Gradle version to 4.1.3, and it worked… I looked at the log and found a strange place.
I added everything in the picture by hand except the red ones, but where did I get the red ones? The reason for the error is probably because of this, I guess it is maven’s cache problem, but I don’t know how to remove it, and I haven’t found relevant information. So the problem lay dormant for two days. I kept looking for the maven cache as the source of the problem, looking through the documentation, and finally found it.
I added a link to build cache, but it says that caching build is disabled by default, but I did add org.gradle.caching=false to gradle.properties. I thought the document was wrong. As to whether there is a mistake, to be verified.
conclusion
Gradle 7.0 has had a lot of problems since it was updated to gradle 7.0. These days I was so frustrated that I almost gave up using the old version, but I thought I would have to accept 7.0 anyway and stick with it.
Refer to the link
Gradle 7.x Maven publish adaptation Are you sure you want to create dependency libraries on JitPack? Android AGP 7.0 ADAPTS to start forcing JDK 11 to build caches using Maven Publish