Androidstudio use tutorial (fifth bullet)

Source: Internet
Author: User

Androidstudio using the tutorial (fifth bullet) Create and Build an Android Studio Project

Here are the next four sections:
-Create projects and modules.
-Work with the project structure.
-Eidt build files to configure the build process.
-Build and run your app.

about how to create Project here does not say that the default Project is created in one app of the Module .

ADD a library module

The next section explains how to Project create one in library module and turn it library into a dependency of the program module .

Create a new library module
    • Click File on the menu New Module and select or on the Project right New Module .
    • After you expand the selection at the bottom of the page More Modules Android Library Next .
    • Enter the name here in order to demonstrate the convenience of the name is called mylibrary after all along Next .
      After you finish opening the Module in, build.gradle you will see the apply plugin: ‘com.android.library‘ instructions that this is a library .
Add a dependency on a library module

The previous step we created mylibrary module , and now we want to app module make dependencies with mylibrary module , but the build system is not yet known,
We need to modify app module the next build.gradle file to add mylibrary module it.

...dependencies {    ...    compile project(":mylibrary")}
Build the project in Android Studio

Android Studiobuild projectClick the menu in the navigation bar above Build and select it, and the status bar at the Make Project bottom of the window will show build the progress.
Click the icon at the bottom right of the window to display it Gradle Console .

In the right column of the window, click on Gradle the window to see all currently available build tasks , double-click inside to task execute.

Build a release version

Click on Gradle tasks the page, expand app in task and then double-click assembleRelease .

Configure the Build

Next MyApplication Project , the following sections are explained:
-Use the syntax from the Android plugin for Gradle in build files.
-Declare dependencies.
-Configure Progurad settings.
-Configure signing settings.
-Work with build variants.

Build File Basics

Android Studio projectsContains one build file , each of which module has a build file name build.gradle .
Here are Project app module the build.gradle files in

Apply plugin:' Com.android.application 'Android {Compilesdkversion +Buildtoolsversion"21.1.1"Defaultconfig {ApplicationID"Com.charon.myapplication"Minsdkversion theTargetsdkversion +Versioncode1Versionname"1.0"} buildtypes {release {RunproguardfalseProguardfiles Getdefaultproguardfile (' Proguard-android.txt '),' Proguard-rules.pro '}}}dependencies {Compile Filetree (dir:' Libs ', include: [' *.jar ']) Compile project (": MyLibrary")}

apply plugin: ‘com.android.application’Declared theGradleis of typeAndroidApplication, this will be the mostbuild tasksAdded in
OneAndroidThe program is special.buildTasks and createandroid {…}To declareAndroidProgram-specificbuildConfiguration.
android {…}Partially configured with allAndroidof the programbuildConfiguration:
-compileSdkVersionIndicates the target of the compilationSDKVersion.
-buildToolsVersionDeclares the currentbuildversion, you can use theSDK ManagerTo download multiplebuildVersion.
Note:It is best to use a higher version ofbuildTool or is and compilation is the targetSDKVersion corresponds to thebuildVersion.
-defaultConfigConfigured withAndroidManifest.xmlImportant settings in the.
-buildTyppesPart of the control of how to gobuildand package your program, the default is to define twobuildType:debug 和 release.debugType with the default
debuggingMark, withdebug keyTo sign,releaseThe version is not signed by default, in the configuration abovereleaseWhen not usedProGuard.
dependenciesPart is inandroid, this section declares the dependencies of themodule。
Note:When you modify the project tobuild filesWhenAndroid StudioA project synchronization is required to import the appropriatebuildConfiguration changes, clickAndroid StudioIn the yellow notification sectionSync Now
To make changes to the import.

Declare dependencies
dependencies {    // Module dependency    compile project(":lib")    // Remote binary dependency    ‘com.android.support:appcompat-v7:19.0.1‘    // Local binary dependency    ‘libs‘, include: [‘*.jar‘])}
    • Module Dependency
      is locally dependent Module .
    • Remote binary Dependency
      For remote dependent binaries, examples of Android SDK all packages in the repository support v7 .
    • Local binary Dependency
      The packages that are dependent on the local project are in the catalog in the jar jar project libs .
Run Proguard

You can use code obfuscation during the build process to ProGuard modify build the options in the file runProGuard true .

...android {    ...    buildTypes {        release {            true            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘‘proguard-rules.pro‘        }    }}...

getDefaultProguardFile(`proguard-android.txt`)Contains the Android SDK default settings at installation time ProGuard . Android Studioin module the root directory
The file is added proguard-rules.pro and you can configure the appropriate ProGuard rules here.

Configure Signing settings

The difference between the

debug version and the release version is that the application can perform debug and APK on some stable devices How to sign it. The build system uses the default signature for the debug version and uses a known
certificate to not code hints during the build process. If you do not specify a signature configuration, the build system does not sign the release version.
Here's how to get the program to sign the release version
-Copy the signature file to the root of app module .
This will ensure that you can find your signature file when you build the project on another machine, and if you do not have a signature file, you can create one first.
-Configure the signature options in build file in app module .
java
...
Android {
...
Defaultconfig {...}
Signingconfigs {
Release {
StoreFile file ("Myreleasekey.keystore")
Storepassword "password"
Keyal IAS "Myreleasekey"
Keypassword "password"
}
}
Buildtypes {
Release {
...
Signingconfig signingconfigs.release
}
}
}
...

    • Android Studio build task Run the page in assembleRelease .
      The app/build/apk/app-release.apk next package is now signed with the signature file.
      Note: It is not safe to write a signature password to a build file, either by configuring the password into an environment variable or by prompting it to enter a password during the build process. Here we first do not describe how to configure, you can search under their own.

As for the beginning of the said use Gradle can be very simple multi-channel packaging will be explained in the future, here first.

    • Email: [Email protected]
    • Good luck!

Androidstudio use tutorial (fifth bullet)

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.