What is the Android Gradle build tool (Android Gradle build tools)?

Source: Internet
Author: User

Reprint Address: http://mrfu.me/android/2015/07/17/New_Android_Gradle_Build_Tools/

Translator Address: "Turn" list of new Android Gradle build tools: New DSL structure and Gradle 2.5

Original: First look at new Android Gradle Build tools:the new DSL structure and Gradle 2.5

Bilingual address: "Turn-bilingual" list new Android Gradle build tool: New DSL structure and Gradle 2.5

  • Translation: MRFU
  • Check: MRFU

The Android Studio 1.3 platform is already close to a stable release, with new features being rolled out, including the perfect support for the NDK. It seems that some major changes are also awaiting the right incubation time, such as: New Gradle build tools and newly designed DSL (Gradle script code structure)

After one hours of playing with me, I found it to be very interesting, so I decided to write this blog to tell you guys about the changes that the build tool is about to make ready for you.

What is the Android Gradle build tool (Android Gradle build tools)?

In case you don't know it yet! The Android Gradle build tool is a runtime used to process files under module build.gradle , before this file is passed to Gradle for further operation.

The Gradle Build Tools declaration in the project build.gradle is as follows:

dependencies {    classpath ‘com.android.tools.build:gradle:1.2.3‘}

Each version of Gradle build Tools works in conjunction with the supported Gradle versions listed below.

Android Gradle Plugin Gradle
1.0.0-1.1.3 2.2.1-2.3
1.2+ 2.2.1+

The syntax rules are defined in Android Gradle Build Tools, and we use the syntax rules build.gradle to write Gradle scripts in a file (and the syntax we used these days to write Gradle S Cript in Build.gradle file was defined in Android gradle build Tools.). We call it DSL (Domain-specific Language).

New Android Gradle Build tool

Since the advent of Gradle build Tools 1.0, the DSL has not been passive and the Android Studio team has decided to make significant changes to the new Gradle build tools. It is still in the experimental phase, by altering its underlying Gradle's new component model mechanism, which significantly reduces the time spent on configuration. However, the development team is trying to remove these generic changes to minimize the migration process from the traditional plugin in the future. (However development teams is working hard trying-remove these current changes-minimize the migration process from The traditional plugin in the future.)

In any case, frankly, the new DSL looks pretty good. I must say I am convinced of these changes because this new DSL structure and naming is more meaningful than it is now.

Try the new Gradle build tools simply by changing the build tools version in the project's build.gradle file:

dependencies {    classpath ‘com.android.tools.build:gradle-experimental:0.1.0‘}

Note that the new build tools will work with the Gradle 2.5 you just released, so you'll need to first install Gradle2.5 and modify the line under your project's gradle/gradle-wrapper.properties file distributionUrl :

distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-bin.zip

Go to the Settings page (Windows system under File-Settings or Mac OS X under Android Studio-Preferences), and make sure that you choose to use the default configuration of Gradle wrapper.

Then modify the module's build.gradle file from this:

apply plugin: ‘com.android.application‘android {    compileSdkVersion 22    buildToolsVersion "23.0.0 rc3"    defaultConfig {        applicationId "com.inthecheesefactory.hellojni25"        minSdkVersion 15        targetSdkVersion 22        versionCode 1        versionName "1.0"    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘        }    }}dependencies {    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])    compile ‘com.android.support:appcompat-v7:22.2.0‘}

Change to this:

 apply plugin: ' com.android.model.application ' model {android {Compilesdkve rsion = Buildtoolsversion = "23.0.0 rc3" Defaultconfig.with {ApplicationID = "Com.inthecheese Factory.hellojni25 "Minsdkversion.apilevel = Targetsdkversion.apilevel = Versioncod E = 1 Versionname = "1.0"}} android.buildtypes {release {isminifyenabled = f Alse proguardfiles + = file (' Proguard-rules.pro ')}}}dependencies {compile filetree (dir: ' Libs ', Include: [' *.jar ']) Compile ' com.android.support:appcompat-v7:22.2.0 '}  

You can notice a big difference in structure. com.android.applicationnow instead com.android.model.application . Most properties require = operators, and += operators are used to add elements (perhaps multiple) to the collection. The names of some of the previous attributes are not very clear, and are now adjusted, for example: Now it's minSdkVersion becomeminSdkVersion.apiLevel

OK, let's use the Gradle file Sync project to apply these changes.

Then you just need to run it. After using more meaningful grammar rules, everything works as expected. Build with the freshly baked Gradle 2.5!

Try the NDK support

Android Studio 1.3 Hooves has announced full support for the NDK. So let's try it out with a very simple example of native code. First, you need to local.properties define an NDK directory in the project's file. Please note that the NDK r10e you can display in the Android NDK Downloads Page and the NDK Bundle shown in SDK Manager are all available.

ndk.dir=PATH_TO_NDK_ROOT

Create HelloJni.java them under your Java package.

public class HelloJni {    public native String stringFromJNI();}

Create a JNI folder in the Src/main directory and create a file that reads hello-jni.c :

Hello-jni.c

#Include <string.h>#Include <jni.h>JstringJava_com_inthecheesefactory_hellojni25_hellojni_stringfromjni(jnienv* env, Jobject thiz) {#If defined (__arm__)#If defined (__arm_arch_7a__)#If defined (__arm_neon__)#If defined (__ARM_PCS_VFP)#Define ABI "Armeabi-v7a/neon (hard-float)"#Else#Define ABI "Armeabi-v7a/neon"#endif#Else#If defined (__ARM_PCS_VFP)#Define ABI "armeabi-v7a (hard-float)"#Else#Define ABI "armeabi-v7a"#endif#endif#Else#Define ABI "Armeabi"#endif#Elif defined (__i386__)#Define ABI "x86"#Elif defined (__x86_64__)#Define ABI "x86_64"#Elif defined (__MIPS64)/* mips64el-* toolchain defines __mips__ too * *#define ABI "Mips64" # elif defined (__mips__) # Define ABI "MIPS" #elif defined (__aarch64__) #define ABI "arm64-v8a" #else #define ABI "Unknown" #endif return (*env) Newstringutf (env,  "Hello from JNI!! Compiled with Abi "Abi ");          

Please do not forget to com_inthecheesefactory_hellojni25 change the package name to the corresponding Hellojni.java, otherwise it is not working.

For those who are familiar with the NDK, you may notice that makefiles is no longer needed.

This is the final file directory:

Now, let's MainActivity.java test this JNI code in, putting the following code into the last line of the Mainactivity class:

public class MainActivity extends AppCompatActivity { ... static { System.loadLibrary("hello-jni"); }}

Modify onCreate It like this:

@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toast.makeText(MainActivity.this, new HelloJni().stringFromJNI(), Toast.LENGTH_LONG) .show();}

Duang~ done! Now, you can use the Java code to native code, run it and try it.

With the amazing full support of Ndk,java code now and Native code on Android Studio you can work with more seamless. If you debug your code in Java, it will jump to the correct location of the native code. (Translator: This is really amazing!) )

Anyway, it's still in the experimental phase, and some of the features are still under development. For serious users, it's best to wait until it's finally released.

Conclusion

I have to say that the new Gradle Build Tools are very interesting. The main changed DSL looks very promising, and has far-reaching implications for the present. Good code should tell us what it can do (translator: can literally understand the meaning of this code), right?

Then it's still in the experimental phase. This DSL is not the final version, we'd better just learn and understand his presence, instead of switching to this new version right now. Anyway, I believe it won't be long before it releases a stable version that can be actually used. Get ready for it!

Quote Original: http://blog.csdn.net/lijinhua7602/article/details/48596955

Blog is to remember that they are easy to forget things, but also a summary of their work, the article can be reproduced, without copyright. Hope to do their own efforts to do better, we work together to improve!

If there is any problem, welcome to discuss together, code if there is a problem, you are welcome to the great God!

What is the Android Gradle build tool (Android Gradle build tools)?

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.