Android Gradle Related Configuration

Source: Internet
Author: User

Sometimes we need to rename the output APK file name, which we wrote before Android Studio 3.0:

Applicationvariants.all {Variant                            -i = output.outputfile                if  null && outputFile.name.endsWith ('. apk ')) {                    // modify APK file name here                    def fileName = Getproject (). Name + "-" + Variant.basename + "-${defaultconfig.versionname}.apk"                     C15>new  File (outputfile.parent, fileName)         }}

But after Android Studio 3.0, this will be an error:

 for Apkvariantoutputimpl_decorated{apkdata=main{type=main, Fullname=debug, filters=[]} of type Com.android.build.gradle.internal.api.ApkVariantOutputImpl.Open File

This error probably means that the OutputFile reference is now "read-only" (read-only) and cannot be re-assigned to a new object.

After the multi-toss verification, the final correct way to do this is:

Applicationvariants.all {Variant                            -i = output.outputfile                if  null && outputFile.name.endsWith ('. apk ')) {                    // modify APK file name here                    def fileName = Getproject (). Name + "-" + Variant.basename + "-${defaultconfig.versionname}.apk"                    = fileName                }            }        }

Need to pay attention to is the original Variant.outputs.each must change to Variant.outputs.all, otherwise also will error of OH.

So if your project is the SDK and not the app, then the flavor changes:

Libraryvariants.all            {variant                -i = output.outputfile                if null && outputFile.name.endsWith ('. Aar ')) {                    // modify APK file name here                    def fileName = Getproject (). Name + "-" + Variant.basename + "-${defaultconfig.versionname}.aar"                    = fileName                }            }        }

Well, that's right, just change applicationvariants to libraryvariants.

Now let's talk about the Maven release script:

First add in the header:

Apply plugin: "maven"' signing '

And then:

// ============ Publish Script ================= // Maven Warehouse Address

Ext. Release_url = ' File://localhost/Users/Admin/mySDK '//local Warehouse
Ext. Snapshot_url = ' File://localhost/Users/Admin/maven-snapshots '

Ext. Release_url = ' http://127.0.0.1:8081/repository/maven-releases/'ext. Snapshot_url= ' http://127.0.0.1:8081/repository/maven-snapshots/'//user name and passwordExt. USERNAME = ' USERNAME 'ext. PWD= ' pwd '//judge version is release or snapshotsdef isreleasebuild () {return!android.defaultconfig.versionname.contains ("SNAPSHOT")}//Get Warehouse URLdef getrepositoryurl () {returnIsreleasebuild ()?Release_url:snapshot_url}uploadarchives {repositories {mavendeployer {beforedeployment { Mavendeployment Deployment-signing.signpom (Deployment)} repository (Url:release_url) {Authentication (user Name:username, Password:pwd)} snapshotrepository (Url:snapshot_url) {Authenticati On (Username:username, password:pwd)} pom.project {version android.defaultconfig.v Ersionname//Version numberArtifactid ' ProjectName '//Project NameGroupId ' Com.demo.test '//package name, or other unique identityPackaging ' AAR '//Packing MethodDescription ' test '//Description            }        }    }}//to digitally signSigning {//When a release version & A "uploadarchives" task existsRequired {isreleasebuild () && gradle.taskGraph.hasTask ("Uploadarchives")} sign configurations.archives}

Of course, MAVEN warehouse address can also be changed to your local address, do not install MAVEN environment.

Here is a pit, once you have been released through MAVEN, found a little problem, changed the code, but did not change the version number and then execute the script re-release, although the script executes successfully, the server actually does not update the package, even if you delete the server package and then publish it is useless, The version number must be updated to be valid, so before releasing release version of the snapshot version verification, verify the release release, to avoid encountering unnecessary problems.

The last is the quote:

Dependencies {     ...      Com.demo.test:test:[email protected] '  }repositories {
Maven {URL ' file://D:/Users/Admin/mySDK '}//local repository
//maven {url ' file://D:/Users/Admin/maven-snapshots '} ' Http://127.0.0.1:8081/repository/maven-releases/' } ' http://127.0.0.1:8081/repository/ maven-snapshots/' } mavencentral ()}

Android Gradle Related Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.