How to import open source projects with Android Studio and solutions to common mistakes this article is on GitHub's hottest materialdesign library, materialdesignlibrary to show you how to use Android Sudio to import open source projects , if you have just transferred from eclipse to as as I did, this article is perfect for you. If you do not introduce any third-party libraries, do not do automated sub-channel packaging, and so on, it can be completely do not understand gradle in the case of the development of Android projects. But if you want to import hot items on GitHub, you must first familiarize yourself with Gradle. 1. Gradlegradle is a groovy-based automated building tool for Java applications, based on DSL syntax. is a new tool that Google introduced to replace Ant and Maven, and it relies on maven and ivy compatibility. Simply put, Gradle is an automated engineering tool introduced by Andriod Studio that solves the build of Android projects. May be able to solve the following development process pain points: do not have to download the third-party library. Before using eclipse, you had to download the third-party library and then introduce the third-party libraries into your project. But with Gradle, a few lines of code take care of third-party libraries, reducing coupling. Instead of manually modifying the N-times code, the code is sent n packets to n markets. Before you might need to send different apk packages for different channels, you can now generate multiple channel packages at once with just a few lines of code in Gradle. Refer to this article for details: How to implement a set of code to develop different features of the APK through Gradle. If you create a new project with AS, the default project structure for this project, the file opened in the diagram is Testme/build.gradle, and the meaning of each sentence has been given. The new project named Testme in the Gradle diagram uses the directory structure of Project. This directory can be seen in the following several gradle files, namely: Testme/build.gradle, Global Gradle, the settings in this file will be common throughout the project. Testme/app/build.gradle, the Gradle of the module, is only common in the app module. Testme/settings.gradle, which specifies which directory is the module model. The contents of the content by default is include ': App ', which means the app folder is a module. The contents of the Testme/app/build.gradle file are explained in detail in the notes in the illustration. Gradle2. Import Materialdesignlibrary Project Our goal is to put mateThe Rialdesignlibrary project runs successfully in as and runs successfully on the phone. 2.1 The first step is to download the materialdesignlibrary locally using the git clone command. 2.2 The second step into As,file->import project, then locate the Materialdesignlibrary directory and double-click the Build.gradle in the directory to import the project. 2.3 The third step Gradle can see the Materialdesignlibrary project on the imported GitHub contains two module, including Materialdesigndemo and a materialdesign. Materialdesign build.gradle File First behavior: Apply plugin: ' com.android.library ', means this is a library. Materialdesigndemo build.gradle File First behavior: Apply plugin: ' Com.android.application ', indicating that this is an application. His project uses a reference to the local materialdesign library, and the third part of this article is to refer to the Materialdesign Library of the online Center library. Both methods are possible, but the latter is more convenient and more common, and the first method is less common. After the second step, many errors can occur, usually due to configuration problems, which are described in the following common error section of this article. Note: Make sure that the setting.gradle inside the root directory is include ': Materialdesign ', ': Materialdesigndemo '. Indicates that all two of these folders are module. 3. Refer to Materialdesignlibrary or the previous Testme project in your project, simply add compile ' to dependencies in Testme/app/build.gradle Com.github.navasmdc:materialdesign:[email protected] ' Can, as follows: 1234567dependencies {//compile all the jar packages under the Libs directory compile Filetree (dir: ' Libs ', include: [' *.jar '])//Multiple file//compile files (' Libs/foo.jar ')//single file so write compile' com.android.support:appcompat-v7:22.0.0 '//compile third-party library compile ' com.github.navasmdc:materialdesign:[email Protected] '}4. Common errors as in importing open source projects or third-party libraries, errors often occur as follows. In fact, a lot of the tools are the version of the problem. 4.1error:failed to find build tools revision 21.1.1 Install build tools 21.1.1 and Sync Project is because the open source library corresponds to the build tools version of your A s not inside. The workaround is to click on his link to download it. or change the buildtoolsversion "21.1.1" in the Build.gradle file inside each model to be the build tolls version inside the machine. 4.2error:failed to find target android-18:/users/xujin/develop/adt-bundle-mac-x86_64-20140702/sdkinstall missing Platform (s) and Sync project is because the open source library corresponds to the version of the Android SDK that is not in your machine. Workaround, either download or change the configuration. Change the Compilesdkversion 21 in the Build.gradle file in each model to be the SDK version inside the machine. 4.3Error: (44, 30) Error: The diamond operator is not supported in-source 1.6 (use-source 7 or later to enable the diamond operator) because there is a list in the code cars = new Arraylist<> (), Java introduced the diamond operator <> in 1.7, there are two workarounds. One is to change the compiled Java SDK version, instead of changing the error code to list cars = new ArrayList () 4.4Error: (PNS) No resource Identifier found FO R attribute ' checked ' in the package ' com.gc.materialdesign ' is because the 37th line of materialdesign:checked= "true", Namespace Materialdesign There is no checked attribute, change to check, the code is as follows. (I've met before, let's talk about it.) ) 12345678 Reference importing-libraries-into-android-studioandroid Studio Series Tutorial Four- Gradle Basic materialdesignlibrary
Android-android Studio Import Open source projects and common errors