Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build an Android project in Gradle

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to build an Android project in Gradle". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to build an Android project in Gradle.

Gradle build script:

Buildscript {/ / define some JAR libraries required by the project LIBS_DIR = ".. / libs" / / you need to get gradle's android plug-in repositories {mavenCentral ()} dependencies {classpath 'com.android.tools.build:gradle:0.4.2'} / / declaration from the central maven library. The project is an android build apply plugin: 'android' dependencies {/ / also use the local maven library to find the dependency repositories {mavenLocal ()} / / here are some jar files compile files ("${LIBS_DIR} / hiscore/hiscore.jar") compile files ("${LIBS_DIR} / GoogleAnalytics/libGoogleAnalytics.jar") needed by app / / this is A project definition android {compileSdkVersion 15 buildToolsVersion "17.0.0" / / built by the android function library compile ('com.mopub.mobileads:mopub-android-sdk:unknown')} / / built by me in the local maven repository (using "aar" format). The code path below is not the recommended new project structure / / I still use the Eclipse style structure sourceSets. {main {manifest.srcFile 'AndroidManifest.xml' java.srcDirs = [' src'] resources.srcDirs = ['src'] aidl.srcDirs = [' src'] renderscript.srcDirs = ['src'] res.srcDirs = [' res'] assets.srcDirs = [' Assets']} instrumentTest.setRoot ('tests')} / / declare the details of creating a signed release signingConfigs {release {storeFile file (".. / keys / android.keystore") storePassword "#" keyAlias "#" keyPassword "#"}} / / declare that this release build needs to run proguard buildTypes {release {runProguard true proguardFile getDefaultProguardFile ('proguard-android.txt') proguardFile' proguard.cfg' signingConfig signingConfigs.release} before signing

To build app from the command line, run the following command:

Gradle assembleDebug # debug build gradle assembleRelease # release build

I have done several projects with Maven before and found it very useful to use Maven to manage project configuration, especially in dependency management. But I find that Maven lacks flexibility in some cases, and you have to customize it for some special cases. In theory you can write your own Maven plug-ins, but in practice most users don't. Usually they rely on existing plug-ins. So I often use Ant instead of Maven because it is more flexible when dealing with project-specific operations, such as copying or modifying code files.

Gradle seems to do well in both areas: full support for most common cases through plug-ins, managing dependencies as well as Maven, and flexibility to customize freely when you need to modify the build script.

Thank you for your reading, the above is the content of "how to build an Android project in Gradle". After the study of this article, I believe you have a deeper understanding of how to build an Android project in Gradle, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report