The generation and introduction of Fragment
Android runs on a variety of devices, including mobile phones with small screens, flat screens with extra large screens and even TVs. In view of the gap in screen size, in many cases, a set of apps is first developed for the mobile phone, and then copied one, and the layout is modified to adapt to the tablet Shenma super large screen. Is it impossible to make an app adaptable to both mobile phones and tablets at the same time? Of course, there must be one. Fragment emerged to solve such problems. You can regard Fragment as an integral part of an Activity interface, and even the Activity interface can be composed of different Fragments. What's more handsome is that Fragment has its own life cycle and receives and handles user events, so there is no need to write a bunch of control event processing code in Activity. More importantly, you can dynamically add, replace and remove a certain fragment.
I learned about Android's Fragment yesterday. According to the official website tutorial, a new class BlankFragment was created, inherited from Fragment. Then an error occurred when compiling:
Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed : Attribute meta-data#@value value=(26.0.0-beta1) from [:design:26.0.0-beta1] :28:13-41 is also present at [:support-v4:26.1.0] :28:13-35 value=(26.1.0). Suggestion: add 'tools:replace="android:value"' to <meta-data> element at :26:9-28:44 to override.
I searched and found that there were all things that I said. The most unreliable one is to change the tags in the manifest file from android:name to class. The log is obviously related to the version! Later, I finally found a solution related to version compatibility. I need to add the following code to the app directory:
{ { DependencyResolveDetails details -> def requested = if ( == '') { if (!("multidex")) { '26.0.0-beta1' } } } }
I tried it and it was indeed good. But you can't be satisfied with this.
Note that just above the added code, the library that is described is the engineering dependency:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation ':appcompat-v7:26.0.0-beta1' implementation ':constraint-layout:1.0.2' implementation ':design:26.0.0-beta1' implementation ':support-v4:26.1.0' testImplementation 'junit:junit:4.12' androidTestImplementation ':runner:0.5' androidTestImplementation ':espresso-core:2.2.2' }
And there is a red line below this line:
implementation ':appcompat-v7:26.0.0-beta1'
The mouse pointer prompts:
All libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.1.0, 26.0.0-beta1. Examples include :support-compat:26.1.0 and :animated-vector-drawable:26.0.0-beta1
This is not very clear: all dependent libraries must use the same version! Look at Dependency, the two versions:appcompat-v7:26.0.0-beta1 and:support-v4:26.1.0 are contradictory! Take a look at the git record. The 26.1.0 line is newly added, which must be automatically added by Android Studio when the BlankFragment class is created. Looking back at the error log, isn’t it the same meaning?
I have to complain about AndroidStudio. Since you want to automatically add version dependencies, you can check the version compatibility together. Otherwise, it would be better not to add it and let us do it ourselves. I hate this kind of semi-automated thing the most, and it is the most deceptive.
In addition, the syntax of the gradle file is also quite interesting. Comments are in the style of C/C++, function declarations are in the style of Python, and Lambda expressions are a bit like C#.
Summarize
The above is the incompatibility issue of the version after adding fragments to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!