Tag Archives: Android

[Solved] Android Studio Error: The binary version of its metadata is 1.5.1, expected version is 1.1.15.

Question:

Android studio reports an error: module 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 1:

Add ext.kotlin in build.gradle of the project_ Version = "1.3.72" (lower version) changed to ext.kotlin_ Version = "1.5.21" (not necessarily 1.5.21, but also the latest version). Just sync and run again

Solution 2:

Open build.gradle under your module (my module name here is MyLibrary) directory, delete some lines in dependencies, and only the corresponding lines in the second figure are left. Just run it again

these lines remain:

[actual record of Android stepping on the pit] Android studio runs with errors. Installed build tools revision 31 is broken

The IDE advised me to reinstall the build tools. After many times of reinstallation, I still reported an error. Then I saw that there was an error in the version 30 of my brother online, and then it was reduced to 29. If I had passed the build, I reduced 31 to 30, and then it passed
obviously, the compatibility and stability of the new version are poor
in the Android of the global build.gradle,
change 31 to 30, as shown in the figure below.
resync and then build.

Android studio installation virtual machine error ® HAXM installation failed.

Android studio virtual machine installation error

Intel ® HAXM installation failed. To install Intel ® HAXM follow the instructions found at: https://github.com/intel/haxm/wiki/Installation-Instructions-on-Windows

After consulting the online materials, it is said that the problems and solutions such as AMD processor and BIOS settings can be checked in this article

My computer is Huawei matebook13, which is definitely not a processor problem. Then I opened the official git address and found out the solution:

Open haxm official Git

 

Click download    haxm-windows_ v7_ 7_ 0.zip, unzip and install the EXE file inside.

After installation, look at Android studio and the problem is solved.

[actual record of Android stepping on the pit] Android studio reports an error invalid gradle JDK configuration found after importing the project

Encountered this problem, as a result, no blog is the right way to deal with it

Error reporting reason

Mismatched configuration files are generated after directly opening the project or importing the project with an incorrect JDK path

Solution

Delete the file with the suffix “. IML” under the. Idea path, and then set the correct JDK path. A JDK is available in the Android studio directory. Then file – & gt; Sync project with gradle files, the IDE will regenerate a matching configuration file and solve the problem.

[Solved] AndroidStudio Error: Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

Error: Could not initialize class com.android.sdklib.repository. [email protected]

After studio installs or upgrades to 4.2 + for the first time, an error is reported in the construction project. The reason is very simple, because the Java path configured for the project is wrong

because the default JDK path of the project will become the JDK path of studio after updating the version. At this time, you need to add your SDK as Java in the “environment variable”_ Home, and then the JDK path of the project must be the same as Java_Home remains the same and error is eliminated

Gradle:Using flatDir should be avoided because it doesn‘t support any meta-data formats.

app.gradle

Code snippet 1:

repositories {
    flatDir {
        dirs 'libs'
    }
}

Code snippet 2:

dependencies {
    classpath "com.android.tools.build:gradle:4.2.2"
}

After gradle is upgraded to 4.2.2, the following prompt message will appear during compilation. Delete & lt; Code snippet 1 & gt; The problem can be solved

Using flatDir should be avoided because it doesn’t support any meta-data formats.
Affected Modules: APP

Use the LIBS directory if necessary

        Add the following code to the project module.gradle

android {
    
    ...

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

Problem solving.

[problem record] installed build tools revision 31.0.0 is broken during Android studio compilation

Error: * * build tool 31.0.0 is missing DX at XXXX (SDK installation address) * * the same error as the title

resolvent

do not use the latest build tools, uninstall the latest packaging tool

Use a different version of build tools instead

Step 1: set up the SDK manager

The setting method is as follows:

    in the top column, select toolsdkmanager, remove the check of Android API 31 and apply SDK platforms as needed, such as Android 11.0 ®, And apply

    The completion result is shown in the figure:

    The second step is to set up the build.gradle file

    1、 Open the build.gradle file in the location shown in the figure
    note: the second build.gradle file opens here. When the mouse is over, module: modulename.app displays

    2、 Modify the contents of the build.gradle file as shown in the figure

    PS: find the SDK version number used by the current simulator

    The current simulator uses the SDK version, which can be viewed by clicking AVD manager in the upper right corner

    or after modifying targetsdkversion, directly click sync and modify it according to the corresponding warning information.

    reference resources:

      [problem record] unity package Android error: & gt; Failed to find build tools revision 30.0.0unity package APK error: failed to find build tools revision 31.0.0 or other versions of Android studio installation, the most detailed in history (more pictures)!! Installation of Android studio (the problem of gradle failure in the supplement is updated on March 10, 2021)

      Thanks to the author of the above article

The ADB server port is changed to 10001, and appium cannot connect to the device

After modifying the ADB server port to 10001, enter ADB devices – L in CMD to successfully detect the device:

Open appium and run the script. The appium running log shows that the device cannot be connected and has been killing the port number 5037 ADB server. The error information is as follows:

I changed the port number of the ADB server to 10001. Why do I still kill 5037?

Seeing this error, when I first thought about it, the environment variable of the modified port was not configured to appium. Click the edit configurations button of appium, and I found that there were no new buttons, but only the default environment variable:

I searched a lot of information on the Internet and found no solution. Finally, I found a solution in an appium Chinese user guide,   Put the guide link here: appium Chinese User Guide – Jianshu (Jianshu. Com)

Modify the running script and add ‘adbport’: ‘10001’ to desired_ In caps Dictionary:

Restart appium, run the script again, connect the device successfully, and solve the problem!

PS: when using appium, you can familiarize yourself with the above instructions and have a general understanding of appium; Then, when running, you should pay attention to the running log. Many problems can be located step by step through the error reporting of the log

[Solved] Manifest merger failed: Apps targeting Android 12 and higher are required to specify an explicit

Android Studio run app error:

Manifest merger failed : Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

Environment used: Android studio 4.2.2, Pixel 2 API 29
Solution reference.
Add android:exported to activity in AndroidManifest.xml file, e.g:

<activity android:name=".MainActivity" android:exported="true">

AVD FFmpeg avcodec_ A solution of open2 returning – 1 (operation not permitted)

I’m working on Android hard decoding recently. Various attempts have been made on the compatible implementation of soft decoding and hard decoding. Later, I suddenly found that it was unable to decode normally, and even failed to open codec appeared.

Use RET = avcodec_ Open2 (CTX, codec, nullptr) the return value is – 1, and the error message is “operation not permitted”. It’s a headache for me. For Android development, permissions, alas AVStream* st = pFormatCtx->streams[streamIdx]; codec_context_ = avcodec_alloc_context3(pCodec); if (!codec_context_) { AVLOGE("Failed to allocate the codec context."); return -1; } if (avcodec_parameters_to_context(codec_context_, st->codecpar) < 0) { AVLOGE("Failed to copy codec parameters to decoder context."); return -1; } if (enable_hw_decode_) { if (codec_context_->codec_id == AV_CODEC_ID_H264) { pCodec = avcodec_find_decoder_by_name("h264_mediacodec"); if (pCodec) { avcodec_free_context(&codec_context_); codec_context_ = avcodec_alloc_context3(pCodec); using_hw_decode_ = true; } } } int ret = 0; if ((ret = avcodec_open2(codec_context_, pCodec, nullptr)) < 0) { AVLOGE("Failed to open codec. ret = %d, %s", ret, PAVUtils::get_error_string(ret)); return -1; }

Because it was copied once at first, but later, if hard decoding was used, the coder was selected again. As a result, the newly applied avcodec context failed to copy the operation parameters from stream to context. When I was using_ hw_ decode_ = Add avcodec before true _ parameters_ to_ context(codec_ context_, st-> codecpar); and it will work normally
it's strange why the relevant parameters are not copied, instead of returning invalid_ Par returns no instead_ What about permit?

Android: Can’t create handler inside thread that has not called Looper.prepare() [Solved]

Error reason:

You can't refresh the UI thread in a subthread in Android

resolvent:

//Refresh the UI using the runOnUiThread method
runOnUiThread(new Runnable() {
    @Override
    public void run() {
        //refresh UI
    }
});

common problem:

When calling locationmanager to get the current location information and upload it in real time, the reason for this error is that locationmanager needs to be used in the main thread. The following methods are recommended:

@Override
protected void onCreate(Bundle savedInstanceState) {    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //upload location messages
    Button btnUploadGPS = (Button)findViewById(R.id.btn_upload_gps);
    if (btnUploadGPS != null){
        btnUploadGPS .setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                uploadGPS();
            }
        });
    }
}

private void uploadGPS(){    
    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER,
            2000,
            (float) 0.01,
            new LocationListener() {
                @Override
                public void onLocationChanged(Location location) {
                    asyncUploadGPS(location);
                }

                @Override
                public void onStatusChanged(String provider, int status, Bundle extras) {

                }

                @Override
                public void onProviderEnabled(String provider) {
                    asyncUploadGPS(locationManager.getLastKnownLocation(provider));
                }

                @Override
                public void onProviderDisabled(String provider) {
                    asyncUploadGPS(null);
                }
            }
    );
}

private void asyncUploadGPS(final Location currentLocation) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            //upload loacation messages
        }
    }).start();
}