Author: 24K pure Handsome bean
Disclaimer: This article is the original 24K pure shuaidou, please do not reprint without the permission of the original author
The preface
As one of the most cutting-edge creatures in the world, it’s hard not to know what’s new. With the preview release of Android 8.1 Oreo on October 26, The official release of Android Studio3.0 was also released. As Android developers, we already know that Google announced support for Kotlin at its Developer conference in May, so a big part of this update is Kotlin support. Let’s explore AS3.0 in the footsteps of LZ
I believe that many people have experienced the experience version of Google dad released early, although the official version has been out, but many people do not dare to update rashly, for fear of falling into the pit can not come (is a timid ape, identification completed)
The installation
If you click on the update from inside Android Studio, you’ll be redirected to the Android website, where you can download the update if you don’t have a ladder:
Problems encountered during installation
Gradle Sync failed
Gradle sync failed: Cause: com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;
Consult IDE log for more details (Help | Show Log) (8s 123ms)
In fact, it was not this error at first, it was a redownload error at first, then LZ deleted the 2.3 version, the cache was cleared, and then it became this error. Here is a solution to StackOverflow
This works for me, too, and I’m fine with demoting ButterKnife. If there are other better solutions, welcome private letter to me, paid to send red envelopes.
“The solution of one problem is to better meet the emergence of the next problem” — Lu Xun
Solution 1: Demote the ButterKnife you rely on in your project to 8.4.0
Solution 2: Reduce gradle plugin to 2.3.3 and recompile it
Unable to resolve dependency for:
At first glance, I thought I did not rely on appCommon in setting.gradle, but I did rely on appCommon after reading it. Besides, it was an old project, which was quite normal in AS2.3 version. I tried adding the Preview node to buildTypes, but it didn’t work. When I saw the error message, I saw signingConfigs, and I thought, gradle has this node. I deleted that node with a try attitude, and then, oh my god, oh my god, it compiled successfully. If there are other better solutions, welcome private letter to me, paid to send red envelopes
Solution: Remove the signingConfigs node from your project. If you’re worried about multi-channel packaging, use the packaging tool instead.
Here are some of the problems that people in the group had:
3, the app: transformDexArchiveWithExterLibsDexMergeForDebug
Solution: Delete the gradle directory on your computer (clear the Gradle cache) and build again
Reference stackoverflow: https://stackoverflow.com/questions/46233560/getting-dexarchivemergerexception-when-adding-leanback-library
Solution steps here: https://asyoulook.com/computers%20&%20internet/android-unable-to-merge-dex/82120
Cannot set the value of this object read-only property ‘outputFile’
Error:(56, 0) Cannot set the value of read-only property ‘outputFile’ for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=debug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
<a href=”openFile:D:\eclipseCode\ipay-android\xinlebao\build.gradle”>Open File</a>
Solution: Modify filename code please write like this
android.applicationVariants.all { variant ->
variant.outputs.all { outputFileName = “xinlebao_${defaultConfig.versionName}_${releaseTime()}.apk” } }
5, AAPT2 compilation error AAPT2 error
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Solution: Turn off APPT2 compilation in gradle.properties
android.enableAapt2=false
Note: If you are a project from Eclipse to as, you may not have the gradle.properties file, please create it manually in the project root directory
6, APT plugin Error:Cannot choose between the following configurations of project :mylibrary
Error:Cannot choose between the following configurations of project :mylibrary:
– debugApiElements- debugRuntimeElements- releaseApiElements- releaseRuntimeElements All of them match the consumer attributes:
Solution: The following
//1. Delete from project build.gradle
The classpath ‘com. Neenbedankt. Gradle. Plugins: android – apt: 1.8’ / / 2. Delete apply plugin: ‘android-apt’//3 from module build.gradle. Dependencyapt will build the module. Gradle file: com. Jakewharton: butterknife – compiler: 8.1.0 ‘/ / annotationProcessor instead ‘com. Jakewharton: butterknife – compiler: 8.1.0’
Ok, those are some of the problems with the recent update 3.0. If you have any other problems, please feel free to send me a message.
Android Studio 3.0
Gradle files
Wow, after the problem is solved, I want to create a new project to see what changes are made. The first big change is the gradle file:
As you can see, Google Dad “killed” the buildToolsVersion build tool. In previous builds, buildToolsVersion also caused a lot of errors in building projects, but now Google Dad “killed” it. Now the dependency is changed to implementation, so what’s the difference between compile and compile? Take your time, have a cup of tea and listen to me:
(1) Compile and API
API is exactly the same as compile, there’s no difference. As we all know, there are a lot of outdated classes and methods as Android versions get updated, so does Compile, which we can think of as the past tense of the API.
(2) API and Implementation
These two instructions are new to AS3.0. Here is a diagram to illustrate the difference between them:
Have students want to learn more about, please refer to the official: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations
Support Kotlin
For those of you who are just beginning to learn Kotlin, AS3.0 supports converting Java code directly into Kotlin code. Let’s take a look at this feature through a VCR:
In the Java File, select the Code you want to Convert and select Code — >Convert Java File to Kotlin File at the top. After converting, this is a Kotlin File.
3, logcat column
In the last few versions of AS, when Logcat was Android Monitor, there were a lot of things in it, such AS network, memory, CPU, etc. In AS3.0, Google split it up and put Logcat out separately. The previous one that looked at network, memory, and CPU was put out separately. There’s something called the Android Profiler:
Isn’t it cool? It also comes with a bag capture function (one of LZ’s favorites). It’s just turned off by default, so we’re going to have to turn it on manually. Go into Run — >Edit Configurations and just hook the following:
It is important to note that the API version in your project must be API26 or below, and your phone version must be Android5.0 or above to use the packet capture feature. Once opened, let’s grab a bag and try:
After making a NETWORK request on the mobile phone, the “NETWORK” column will change obviously. We select that area for packet capture, and we can see that an interface MainServlet is requested (if multiple interfaces are requested in this area, it will be listed one by one). Then we click “MainServlet”. There will be background transmission of Json, Header and other information, how, is not very cool, no longer bother to test to help you catch the package, also do not have to install any other software. The CPU and MEMORY, too, have data that records the current page, and you can analyze it accordingly. These two will not show, interested students can update after their own play. Finally, it is important to note that turning this on slows down the build of your application, so only turn it on when you are about to start profiling your application.
4. File manager
In AS3.0, the file manager tool allows seamless interaction with your AS-connected phone. You can view, copy, and delete files on the device. This is useful when checking files created by an application or when talking about transferring files to a device:
Data /data/app_name/ Contains application data files stored on internal storage sdcard/ contains user files (pictures, etc.) stored on external user storage
5. Support Java8
You can format Java code directly in lambda format, but you need to set your project to support Java8. Right-click your Module and select Open Module Settings. After entering, follow the following Settings:
So you can use lambda expressions, and the system will automatically remind you where to convert to lambda expressions, whether it is good or not:
reference
http://blog.csdn.net/soslinken/article/details/73114637
http://blog.csdn.net/niubitianping/article/details/72600923
http://www.jianshu.com/p/9af06314e036
Recommended reading
1. Android tips: This covers all the ways to “exit an App with one click”
Android DataBinding & MVVM
3. I don’t write a line of code to implement the Toolbar! And you’re still wrapping BaseActivity?