Android Project Development Encounters problems (64K of errors) in the way of resolution, from into the pit to the pit

Source: Internet
Author: User

Own an Android project, has been progressing smoothly, did not encounter any serious problem, today is ready for colleagues to install a mobile phone to play, who knows embarrassing lost, unable to build apk! Error! My God, I developed no problem ah, my phone connected to USB, and then Android studio inside run, very smooth, able to properly install.

But to change colleague's cell phone but not, compile error, no, try again my cell phone, still normal, change colleague mobile phone can't!!

My first reaction is the phone version problem! Sure enough, my phone is 6.0, while the phone is still: 4.4.4, OK, go to see my project configuration:

Well, seems to support the 4.4.4 Ah, for woolen?

Look at the error message (My way of jumping to the pit starts here):

The second mistake can not understand, but the first second understand, the legendary 64K,, the number of methods beyond:

There is a website, but need FQ, Ken English Bar, will not fq the children's shoes Baidu Many official solution translation, about the steps are as follows:

1. Add a Multidex package reference, however, added in the Dependenices tab of the Android studio module but not found, empty

Add it directly, modify it in the Build.gradle file: as below,

Added: Compile ' com.android.support:multidex:1.0.0 '

Modify Defaultconfig configuration: Add:

Multidexenabled = True

Android{
Compilesdkversion +
Buildtoolsversion"21.1.0"

Defaultconfig{
...
Minsdkversion -
Targetsdkversion +
...

//enabling Multidex support.
Multidexenabledtrue
}
...
}

Dependencies{
Compile' com.android.support:multidex:1.0.0 '
}

3. Modification of Manifest declaration

<?XML version="1.0"encoding="Utf-8"?>
<manifest xmlns:android="Http://schemas.android.com/apk/res/android"
Package="Com.example.android.multidex.myapplication">
<application
...
Android:name="Android.support.multidex.MultiDexApplication">
...
</application>
</manifest>

Remember to clear the project before the next step, will load the ' com.android.support:multidex:1.0.0 ' package

If you have your own application, inherit mulitdexapplication. If the current code has been inherited from other application can not modify that also line, rewrite application's Attachbasecontext () this method. Since I have my own application for catching exceptions, I'm going to inherit

Originally:

After modification:

Reference Address: Http://blog.zongwu233.com/the-touble-of-multidex

To this finish, compile the project, after a long wait, compile, Error!!!

Well, this mistake is probably a memory overflow or something like that.

Google has a website: http://www.tuicool.com/articles/bEFNJj

Get the processing method, add in the Build.gradle, the specific explanation look above the website:

OK, finally finished:

Successfully compiled APK:

To this, 64K no longer error, see the results rar compression after two Dex files, is the method to separate it

This is the end of the 64K solution!

Note: The project has several functions: how can the number of methods exceed 64K, and the analysis apk file is 7 m large?

Deep analysis of root causes:

My project on a login page + a registration page + 2 function pages, altogether also less than 10 functions, how the number of methods will be super, feel this is the root cause of the problem, do not solve the problem, is a palliative solution does not cure!!

So, Google again Google, finally I found an article,

http://blog.csdn.net/qq376430645/article/details/49885399

Started my apk analysis path:

Follow the article guidelines: Analyze my apk method number composition, one of which caught my attention:

Google's? The number of methods accounted for nearly 5W, no wonder, and analysis of other people's apk, there is no this, so the basic lock is the problem, and then see if the project refers to some of Google's things? A look, there really is a:

This is it, I don't seem to have used this ah, when added, do not know, tube him, delete

Delete, compile:

Error, analysis of it:

This guy in the project:

You know, these are the things I added when I studied fragment.

All right, it's totally useless.

Re-compile, normal, just to solve the 64K problem when the modified and added code are restored,

Compile, Normal:

APK size 3M A little more, reduced by half!!!

End!!!!!

About the solution of 64K problem, adopted the simplest, in which the reference URL mentions which QQ,,FB solution, because the technology is limited, has not the courage to realize!!

Reference:

Https://developer.android.com/studio/build/multidex.html

Http://blog.zongwu233.com/the-touble-of-multidex

Http://www.tuicool.com/articles/bEFNJj

Http://dwz.cn/3TFLCx

Android Project Development Encounters problems (64K of errors) in the way of resolution, from into the pit to the pit

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.