Tag Archives: Android

How to Solve Project Upgrade to flutter2.5.0 Error

Record an error report about the error report after the project is upgraded to 2.5.0

error message 1:

Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.

Solution:
in your project level gradle file, just increase ext.kotlin.version from any version you have to "1.4.32" or any latest version available. Path:/Android/build. Gradle

buildscript {
    // ext.kotlin_version = '1.3.50'
    ext.kotlin_version = '1.4.32'
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google'}
        maven { url 'https://maven.aliyun.com/repository/jcenter'}
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
        // google()
        // mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google'}
        maven { url 'https://maven.aliyun.com/repository/jcenter'}
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public'}
        // google()
        // mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Error Message 2:
D8: Cannot fit requested classes in a single dex file (# methods: 76688 > 65536) com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
The shrinker may have failed to optimize the Java bytecode.
Solution
Path: /android/app/build.gradle,Change the minSdkVersion version to a larger one, e.g. 21

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.good_commodity"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

[Solved] Android9.0 App Install Android4.4 Error: InflateException-You must supply a layout_height attribute.

Problem description: Android 9.0 application installed to Android 4.4 reports an error InflateException, prompting you must provide a layout_height property.
Android9.0 application installed to Android4.4 reports an error InflateException, prompting you must provide a layout_height property.
Stack.

0-26 11:19:23.312 10710 10710 E AndroidRuntime: FATAL EXCEPTION: main
10-26 11:19:23.312 10710 10710 E AndroidRuntime: Process: com.XX.app, PID: 10710
10-26 11:19:23.312 10710 10710 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XX.app/com.XX.view.player.VideoPlayActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class com.XX.widget.TvXXControlView
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5047)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:658)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
10-26 11:19:23.312 10710 10710 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #16: Error inflating class com.XX.widget.TvControlView
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:170)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at com.XX.view.player.BaseVideoPlayActivity.onCreate(BaseVideoPlayActivity.java:90)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.Activity.performCreate(Activity.java:5294)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     ... 11 more
10-26 11:19:23.312 10710 10710 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at java.lang.reflect.Constructor.constructNative(Native Method)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.createView(LayoutInflater.java:594)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     ... 22 more
10-26 11:19:23.312 10710 10710 E AndroidRuntime: Caused by: java.lang.RuntimeException: Binary XML file line #17: You must supply a layout_height attribute.
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:492)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:5949)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.ViewGroup$MarginLayoutParams.<init>(ViewGroup.java:6117)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.widget.RelativeLayout$LayoutParams.<init>(RelativeLayout.java:1225)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:1062)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.widget.RelativeLayout.generateLayoutParams(RelativeLayout.java:82)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.rInflate(LayoutInflater.java:757)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at android.view.View.inflate(View.java:17465)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at com.xx.widget.TvControlView.<init>(TvControlView.java:132)
10-26 11:19:23.312 10710 10710 E AndroidRuntime:     at com.xx.widget.TvXXControlView.<init>(TvXXControlView.java:64)

 

Solution:
This problem actually has nothing to do with the version, but with the screen allocation rate. The layout xml defines the layout_height referencing the constant defined in the values, but the definition is only defined in the directory of the specific resolution. So the solution Define the referenced value in the values directory

[Solved] Android 9.0 APP Install Android 4.4 Error: IllegalArgumentException

 

Problem Description.
App works on Android 9.0, but the installation to version 4.4 program crashes with the error:

IllegalArgumentException
10-25 17:07:12.475 14178 14178 E AndroidRuntime: FATAL EXCEPTION: main
10-25 17:07:12.475 14178 14178 E AndroidRuntime: Process: com.xx.app, PID: 14178
10-25 17:07:12.475 14178 14178 E AndroidRuntime: java.lang.RuntimeException: Unable to create service com.xx.service.XXService: java.lang.IllegalArgumentException:

 

Stack:

10-25 17:07:12.475 14178 14178 E AndroidRuntime: FATAL EXCEPTION: main
10-25 17:07:12.475 14178 14178 E AndroidRuntime: Process: com.xx.app, PID: 14178
10-25 17:07:12.475 14178 14178 E AndroidRuntime: java.lang.RuntimeException: Unable to create service com.xx.service.XXService: java.lang.IllegalArgumentException: MediaButtonReceiver component may not be null
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.app.ActivityThread.handleCreateService(ActivityThread.java:2582)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.app.ActivityThread.access$1800(ActivityThread.java:135)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5047)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
10-25 17:07:12.475 14178 14178 E AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:658)

 

Solution:
Register MediaButtonReceiver in Manifest

<receiver android:name="androidx.media.session.MediaButtonReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_BUTTON" />
    </intent-filter>
</receiver>

[Solved] AndroidStudio Error: checkDebugAarMetadata & CheckAarMetadataWorkAction

Description

Execution failed for task ':app:checkDebugAarMetadata'.

> Multiple task action failures occurred:

   > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction

      > The minCompileSdk (31) specified in a

        dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)

        is greater than this module's compileSdkVersion (android-30).

        Dependency: androidx.recyclerview:recyclerview:1.3.0-alpha02.

If you upgrade to compilesdk 31 according to the prompt, you are faced with a large number of Android 12 and below are not available, and upgrade the current jdk8 to jdk11 or above, but the set of source code was still available more than 2 months ago. Now it is not available for no reason, which is not in line with the routine.

If the current compilesdk is kept at 30 or 28, gradle compiles and passes, but the above error is reported when running debugging.

I can’t understand it.

Solution:

Take the following three steps to finally solve the problem
1. keep the current compilesdk at 30 or 28.

2. lower the corresponding version number of dependent components, such as dependency: Android. Recyclerview: recyclerview: 1.3.0-alpha02. Change the original version number of the corresponding gradle file from 1. + to 1.2. +, that is, lower the version number by one. Shape such as

The original gradle file is implementation 'androidx.recyclerview:recyclerview:1.+'// means 1.xx latest version, maybe 1.0, 1.1, 1.2, 1.3, 1.4, 1.5 in that order

Now read
implementation 'androidx.recyclerview:recyclerview:1.2.+'// means 1.2.xx latest version, maybe 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5 in that order

3. After recompiling, debug and run again, and the prompt of the dependent component does not appear again, indicating that the modification is effective. By analogy, reduce the version number of other dependent components until similar prompt no longer appears, and the problem is solved.

Plugin Error: Plugin “Android Code Generator“ is incompatible (supported only in IntelliJ IDEA)

1. Question

Plugin Error: Plugin “Android Code Generator” is incompatible (supported only in IntelliJ IDEA).

2. Solution

C:/Users/Admin/AppData/Roaming/Google/AndroidStudio4.2/plugins

After deleting the file, restart the as to solve the problem.

3. Detailed steps

1. Enter the directory of Disk C and click the [user] folder

2. Find the directory of your [administrator] user name, that is, admin above

3. If you enter at this time, you may not find the appdata folder, so you need to open the hidden directory to see it (take win10 as an example here)

4. Follow the above file path to find the directory where the file is located

5. Delete the error folder. This is Android codegenerator plugin IntelliJ

6. Restart Android studio

socket java.net.BindException: bind failed: EACCES (Permission denied)

It took a long time today to find out the real problem.

There are two situations most likely to cause the whole exception:

1. No permission is given;

a. Permission application is not added in androidmanifest.xml;

<uses-permission android:name="android.permission.INTERNET"/>

b. The format of permission application is incorrect

<!-- Mistake -->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

c. The permission is manually shielded by the user;

2. Port less than 1024; Set a larger one, not more than the largest one;

The application could not be installed: INSTALL_FAILED_USER_RESTRICTED

Android studio gives the following error after clicking “run app”

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_USER_RESTRICTED

List of apks:
[0] 'E:\MyProject\xxx\app\build\outputs\apk\debug\xxxxx_.apk'
Installation via USB is disabled.

Troubleshooting steps:

1. It may be that the USB installation is not enabled in the developer option. Check whether it is enabled and try again

2. It is possible that the application tag of androidmanifest.xml has been added

android:appComponentFactory=""
tools:replace="android:appComponentFactory"

Delete this attribute and try again.

How to Solve Error: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

When installing a debug package, the prompt is as follows

C:\Users\test>adb install "C:\Users\test\Downloads\test.apk"
Performing Streamed Install
adb: failed to install C:\Users\test\Downloads\test.apk: Failure [INSTALL_FAILED_TEST_ONLY: installPackageLI]

Solution:

adb install -t "C:\Users\test\Downloads\test.apk"

ADB install has lrtsdg six options

-L lock the application
– R replace the existing application, that is, force installation
– t allow the test package
– s to install the application on the SD card
– D allow it to be installed, that is, the installed version is lower than that on the mobile phone
– G grant all runtime permissions to the application

Failed to find Build Tools revision 30.0.3 [How to Solve]

After we solved the problem of could not resolve com.android.tools.build: gradle: 7.0.2, we reported this error in build output

The most direct solution is to download the version of Android SDK build tools in SDK tools. The path is file >settings> Appearance& Behavior> System Settings> Android SDK> SDK Tools. Unfortunately, I couldn’t download it, so I changed the buildtoolsversion in APP/build.gradle to “31.0.2” of all my current 31.0.2 versions

In the project structure, we have also changed everything, but after running, we still report such an error

After I changed the version to 30.0.2, I still have this problem. Obviously, I have this version, but why not? When I checked my SDK tools, I found that 31.0.0 and 30.0.2/28.0.3/27.0.0 are under Android SDK build tools 31

So I guessed whether it could not be found under the file, so I deleted all except the 30.0.2 version I currently use

Close Android studio and open it again. Success