Tag Archives: Android studio

[Solved] Ubuntu20.04 Error: “Failed to install the following Android SDK packages as some licences have not..“error

After installing Android studio under Ubuntu, importing the project and building, the following error appears:

The problem is that licenses are not matched well

There are only two steps to solving the problem:

1. Open file – & gt; Settings

After the settings interface appears, enter appearance – & gt; System Settings -> Android SDK -> SDK Tools

Download Android SDK command line tools (latest) in SDK tools interface

2. After downloading, CMD line tools will be installed in the SDK directory ~/Android/SDK by default. If your directory is different, you need to modify it accordingly

Execute on the command line

yes | sudo ~/Android/Sdk/cmdline-tools/latest/bin/sdkmanager --licenses

The problem is solved. Build can run normally

Note: 1. In some articles, you can directly run the sdkmanager under ~/Android/SDK/tools/bin /, which will report an error

 java.lang.NoClassDefFoundError

The reason is that Ubuntu 20.04 installs OpenSDK 11 by default, which will conflict with the JRE that comes with Android Studio.
Uninstalling OpenSDK 11 and installing a lower version of JavaSDK is more troublesome.

[Solved] ViewBinding Error: java.lang.ClassCastException: android.widget.RelativeLayout cannot be

prompt: after the article is written, the directory can be automatically generated. For how to generate it, please refer to the help document on the right </ font> for details

Java.lang.classcastexception encountered when using viewbinding: android.widget.relativelayout cannot be cast to cast to android.widget.textview

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/back"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:text="Back" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Title"
        android:textSize="20sp" />

    <Button
        android:id="@+id/done"
        android:layout_margin="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:text="Done" />

</RelativeLayout>

In the XML of the title, the ID of textview is title

<include
        android:id="@+id/title"
        layout="@layout/titlebar" />
        

Use include < in the main interface>  When introducing a layout, the layout ID set is also the title,
when using viewbinding, there will be confusion, so the ID name should be set to different.

[error record] as compilation error (Android support plugin version is too high | upgrade Android studio to the latest version)

Contents of articles

1、 2. Solutions

1、 Error information


Clone a piece of code from GitHub. The following error occurs when compiling;

Download https://services.gradle.org/distributions/gradle-6.7.1-bin.zip (102.84 MB)
Download https://services.gradle.org/distributions/gradle-6.7.1-bin.zip finished succeeded, took 1 m 55 s 666 ms
Starting Gradle Daemon...
Gradle Daemon started in 4 s 99 ms
> Task :prepareKotlinBuildScriptModel UP-TO-DATE
AGPBI: {"kind":"warning","text":"Please remove usages of `jcenter()` Maven repository from your build scripts and migrate your build to other Maven repositories.\nThis repository is deprecated and it will be shut down in the future.\nSee http://developer.android.com/r/tools/jcenter-end-of-service for more information.\nCurrently detected usages in: root project 'Plugin_Hook', project ':app'","sources":[{}]}

FAILURE: Build failed with an exception.

* What went wrong:
This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.2 or newer.

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
com.intellij.openapi.externalSystem.model.ExternalSystemException: This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.2 or newer.
	at org.jetbrains.plugins.gradle.model.ProjectImportAction.addBuildModels(ProjectImportAction.java:273)
	at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:131)
	at org.jetbrains.plugins.gradle.model.ProjectImportAction.execute(ProjectImportAction.java:56)
	at org.gradle.tooling.internal.consumer.connection.InternalBuildActionAdapter.execute(InternalBuildActionAdapter.java:79)
	at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner$ActionRunningListener.runAction(ClientProvidedPhasedActionRunner.java:120)
	at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner$ActionRunningListener.run(ClientProvidedPhasedActionRunner.java:110)
	at org.gradle.tooling.internal.provider.runner.ClientProvidedPhasedActionRunner$ActionRunningListener.buildFinished(ClientProvidedPhasedActionRunner.java:104)
	at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
	at java.lang.Thread.run(Thread.java:748)



* Get more help at https://help.gradle.org

BUILD FAILED in 8m 33s

2、 Solutions


Core error information:

This version of the Android Support plugin for IntelliJ IDEA (or Android Studio) cannot open this project, please retry with version 4.2 or newer.

The current Android support plug-in can’t open the project. Upgrade Android studio to

four point two

four point two

Version 4.2 or above;

Re installing Android studio always fails to install SDK when installing software (solution)

**

Android studio cannot install the SDK when the software is installed

**
I don’t know what’s going on. Android’s AVD can’t be started. It’s stuck in the loading place all the time, indicating that it can’t respond. No matter it’s forced to shut down AVD or recreate one, it can’t be solved, so I decided to reload Android studio. However, when I uninstall Android and delete all the files and then install Android studio again, it always shows that the SDK has been installed and the project cannot be started because there is no SDK. As shown in the figure

finally, with the help of the teacher, I can use the new Android studio again!! Tearful eyes
specific operation:

    uninstall the current Android studio and delete the SDK, gradle, AVD and other folders in the installation directory. Find the. Android studioxxxx and. Gradle folder in the computer user directory, and then delete them. Go to the hidden appdata folder, go to the roaming folder, and then go to the Google folder to delete Android studio XXX. Everyone’s catalog may be different. The last and most important step: restart the computer( I just didn’t restart, so every time I reload, I will display SDK installed Installing Android studio is the same as installing it for the first time. Ha ha

After Android studio creates a new bottomnavigationactivity, there is a blank solution in the upper area of fragment

Problem description

For example, the screenshot is as follows, which is often empty above and incomplete below (recyclerview list) (blocked by the navigation bar at the bottom)

Problem solving ideas

After switching to another fragment, it is found that it is also lower than the whole, so it should be the whole setting problem, so the problem is located to activity_ Main.xml or mobile_ In navigation. XML, which is used to specify the newly created fragment, it turns out to be an activity_ Main.xml specifies mobile_ There’s a problem with navigation’s fragment.

Problem solving

At activity_ In main.xml

    deleting the paddingtop attribute of the outermost constraintlayout will @ + ID/NAV_ host_ Layout of fragment_ Height is set to 0dp

    result


Could not install Gradle distribution

Could not install Gradle distribution

New computer, new Android studio 4.2, new first project error:

Could not install Gradle distribution from 'https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip'

Solution:
(1) click the link in the error message:
1 https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
Download the compressed package to the specified path and unzip it
(2) click file – & gt; Settings-> Build, Execution,Deployment-> Build Tools-> Gradle, in the gradle projects area, change use gradle from to your own download path, retry:

(3) Successful solution:

Gradle tasks disappeared after upgrading Android stuido 4.2?

Recently, many people asked that after upgrading Android studio 4.2, tasks could not be seen in the gradle window

Before 4.2
4.2, there were only dependencies and no tasks

The answer is found in the official issue:

https://issuetracker.google.com/issues/185420705

Gradle task list is large and slow to populate in Android projects. This feature by default is disabled for performance reasons. You can re-enable it in: Settings | Experimental | Do not build Gradle task list during Gradle sync.

Gradle tasks is closed by default due to performance problems. You can open it in the following ways:

File -> Settings -> Experimental

Remove the check below

Do not build Gradle task list during Gradle sync

After re engineering sync, you can see gradle tasks.

Flash back problem when Android studio plays music in sdcard through intent

Code

Add a button in the layout file, set listening events for button in the main class, and play music through intent

1. Write activity_ main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <Button
        android:id="@+id/btn_click"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:gravity="center"
        android:padding="8dp"
        android:text="@string/click4" />

</LinearLayout>

2. Import music into virtual machine

There is a device file explorer in the lower right corner of Android studio. After opening, you can see the file directory of the virtual machine. Find/MNT/sdcard/music, right-click upload and select the music to be imported. The file name should not appear in Chinese

3. Write mainactivity.class

package com.ch5_2;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import java.io.File;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        findViewById(R.id.btn_click4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                //Get the file path, the path is the virtual machine memory card path
                Uri data = Uri.fromFile(new File("/mnt/sdcard/Music/nogoodbye.mp3"));
                intent.setDataAndType(data,"audio/*");
                startActivity(intent);
            }
        });
    }
}

Questions

1. Flashback

Here, the version of the virtual machine will affect the operation. If the version is too high, it will flash back. I used to use Android 11.0, but as soon as I click button, it will flash back. The reason should be the compatibility problem. Change to a lower version

here is Android 5.0

2. This file type problem is not supported

When changing to a lower version of the virtual machine, you may encounter the problem that Android music playing software does not support this type of file. I used MP3 file at the beginning, and the result shows that it does not support it. It’s OK to change to WAV format.

Android studio Error:Execution failed for task ‘: app:transformResourcesWithMergeJavaResForDebug ‘

Android studio error Error:Execution failed for task

Recently, when doing the face recognition check-in system based on Android platform, after importing the third party’s lib package, Android studio reported the following error:

Error:Execution failed for task ‘: app:transformResourcesWithMergeJavaResForDebug ’.
com.android.build . api.transform.TransformException : com.android.builder . packaging.DuplicateFileException : Duplicate files copied in APK META-INF/LICENSE
File1: E:\Workspaces\Swface\app\libs\httpcore-4.4.4.jar
File2: E:\Workspaces\Swface\app\libs\httpclient-4.5.2.jar

After consulting the data, it is found that there are duplicate contents loaded in the meta-inf directory of the jar package. Open the corresponding jar package
sure enough, both of the two jar packages have license, and further Click to find that the contents are exactly the same. However, it seems that the next three files are also duplicate (only there is no clear prompt in the error report), so we can solve them all at once
all Now that we know that it is caused by repeatedly loading files, the solution is to remove the repeatedly loaded files during compilation. The specific operations are as follows:

    1. Open app\ build.gradle File
    1. 2. Modify the configuration as follows:
buildTypes {
          ...... (omit part of the code)
          // Add the following code here
          packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/ASL2.0'
            exclude 'META-INF/notice.txt'
        }
 }       
``

3. Rebuild project

A link to the original text is attached

http://stackoverflow.com/questions/34031395/errorexecution-failed-for-task-apptransformresourceswithmergejavaresfordebug

Android studio upgrade 4.1 plug-in error

reason

The plugins plug-in failed

terms of settlement

1. Delete plug-in
user directory

\AppData\Roaming\Google\Android studio4.1\plugins

Find the directory and delete the corresponding plug-in
uninstall butterknife zelezny and install Android butterknife injections (support kotlin)
uninstall gsonformat and install gsonformatplus

2. The code is not highlighted and the error is not red

Errors don’t pop up, and they don’t pop up without this layout (I have already solved this problem)
don’t create an XML file according to the prompt

3. Code writing does not prompt

Click the file in the upper left corner to find the power save mode. If it is checked, you can cancel the check and restart studio.