Tag Archives: Android studio

Failed to transform file ‘xxx‘ to match attributes [How to Solve]

Failed to transform file ‘xxx’ to match attributes when opening previous projects.

I opened the previous project and encountered a Failed to transform file ‘xxx’ to match attributes error.

There is a problem with the added dependency cache

Solution:

C:\Users\Administrator\.gradle\caches\modules-2\files-2.1 directory, find the conflicting files, delete them, and recompile

Supplement:

If an error is reported:

Null extracted folder for artifact: ResolvedArtifact(componentIdentifier=cn.jiguang.sdk:janalytics:2.0.0, variantName=null, artifactFile=C:\Users\dell\.gradle\caches\modules-2\files-2.1\cn.jiguang.sdk\janalytics\2.0.0\4abdfc462a6164fa5629301f8682a8adb7d3d332\janalytics-2.0.0.aar, extractedFolder=null, dependencyType=ANDROID, isWrappedModule=false, buildMapping={__current_build__=D:\Android\project\build\。。}, mavenCoordinatesCache=com.android.build.gradle.internal.ide.dependencies.MavenCoordinatesCacheBuildService$Inject@5859a341)

This error is also caused by file conflicts

[Solved] Android resource linking failed, error: failed linking references.

Problem description

Android studio 4.0.1 in APP/build Gradle declares to use appcompat-v7, and the compilation times the following errors:

Android resource linking failed
Output:  D:\code\demo\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
D:\code\demo\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
D:\code\demo\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:1086: error: resource android:attr/fontVariationSettings not found.
D:\code\demo\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:1087: error: resource android:attr/ttcIndex not found.
error: failed linking references.

Command: D:\gradle\caches\transforms-1\files-1.1\aapt2-3.2.1-4818971-windows.jar\67766513f93fbda68bd5705c60a70b26\aapt2-3.2.1-4818971-windows\aapt2.exe link -I\
        D:\Android\SDK\platforms\android-27\android.jar\
        --manifest\
        D:\code\demo\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        D:\code\demo\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @D:\code\demo\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        D:\code\demo\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.demo\
        -0\
        apk\
        --output-text-symbols\
        D:\code\demo\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.1-4818971-windows Daemon #0

Solution:

In the root directory gradle In the properties file, disable Android X:

# android.useAndroidX=true
# android.enableJetifier=true

It can be solved by rebuilding.

[Solved] Could not identify launch activity: Default Activity not found Error while Launching activity

Could not identify launch activity: default activity not found appears in Android studio Error while Launching activity

Check androidmanifest Are the following settings in XML

Solution: Configure the following code for the activity to be started

<intent-filter>
	<action android:name="android.intent.action.MAIN" />

	<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

[Solved] fragment error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}…

1. Error Messages:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myapplication/com.example.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Binary XML file line #9 in com.example.myapplication:layout/activity_main: Error inflating class fragment.
2. Locating the problem
Check the logs and find that the problem is located at: at com.example.myapplication.MainActivity.onCreate(MainActivity.java:11), click to jump to the line of code that says

  setContentView(R.layout.activity_main);

It was found that it was an XML file problem, so I carefully checked a piece of code I used fragment

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <fragment
        android:name="com.example.myapplication.fragment.MyFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

It was found that the problem was caused by the fact that the fragment did not use the layout ID. after I added the ID to the fragment, the problem was successfully solved.

 <fragment
        android:id="@+id/my_fragment"
        android:name="com.example.myapplication.fragment.MyFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

[Solved] CommandWithNoStdoutInvokationFailure Unable to start ADB server.

Error: CommandWithNoStdoutInvokationFailure: Unable to start ADB server. Please make sure the Android SDK is installed and is properly configured in the Editor
Error:

CommandWithNoStdoutInvokationFailure: Unable to start ADB server. Please make sure the Android SDK is installed and is properly configured in the Editor. See the Console for more details.
UnityEditor.Android.Command.RunWithShellExecute (System.String command, System.String args, System.String workingdir, System.String errorMsg) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.ADB.StartServer () (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.ADB.Run (System.String[] command, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.AndroidDeploymentTargetsExtension.GetKnownTargets (UnityEditor.DeploymentTargets.IDeploymentTargetsMainThreadContext context, UnityEditor.ProgressHandler progressHandler) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.PostProcessor.Tasks.CheckDevice.GetTargetDevices (UnityEditor.Android.ADB adb) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.PostProcessor.Tasks.CheckDevice.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at <61e151d28db74087bf4788498b7351e6>:0)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

 

Solution:

This problem is only applicable to windows, if it is linux or mac, please follow the relevant instructions to use the shell statement to configure in the termination.
If the sdk is installed on Windows, enter cmd in the run, call up the windows command line, enter adb, and the system feedback says that it is not a system command. . . . .
The solution is simple:
Go to the tools directory under the Android sdk directory, find two files, adb.exe and AdbWinApi.dll, select them, copy them, and paste them in the system directory /windows/system32/.
Then enter adb in the command line, the problem is solved!

[Solved] AAPT: error: resource android:attr/lStar not found

Recently, I want to try the KTX expansion Library of Android core in the project:

implementation "androidx.core:core-ktx:1.7.0"

After adding dependency, we happily start to use various concise syntax sugars provided by KTX to fly happily~

Once running, wow, I reported an error:

Android resource linking failed /Users/xxx/.gradle/caches/transforms-2/files-
2.1/5d04bb4852dc27334fe36f129faf6500/res/values/values.xml:115:5-162:25:
 AAPT: error: resource android:attr/lStar not found.

 

Solution 1:

If the dependency method is
AndroidX.Core: core-ktx:+
you need to replace it with a specific version
AndroidX.core:core-ktx:1.6.0

Solution 2:

If the version is  1.7.0, the compilesdkversion of the project is 31, because my project is 30, an error will be reported and changed to 1.6.0 version is good

[Solved] Android Studio Error: CreateProcess error = 206 file name or extension is too long

When Android studio develops Android projects, the error “CreateProcess error = 206” is easy to appear every time it runs. The console error message says that the file name or extension is too long. I used openjdk to solve this problem. I found many ways to solve it. For a long time, I can only restart Android studio or forcibly end the JDK process in the application manager. Later, I just changed the open JDK to Oracle JDK.

How to Solve Junit Unit Test Error: “No runnable methods“

Abnormal

The errors reported by JUnit unit test are as follows:

java.lang.Exception: No runnable methods

	at org.junit.runners.BlockJUnit4ClassRunner.validateInstanceMethods(BlockJUnit4ClassRunner.java:191)
	at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:128)
	at org.junit.runners.ParentRunner.validate(ParentRunner.java:416)
	at org.junit.runners.ParentRunner.<init>(ParentRunner.java:84)
	at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:65)
	at org.junit.internal.builders.JUnit4Builder.runnerForClass(JUnit4Builder.java:10)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
	at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
	at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
	at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:221)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)

error code

import org.junit.Test;

public class Test01 {

    @Test
    public void test(){
        System.out.println("hello world");
    }
}

reason

There is no problem with the code @ test annotation is placed on the method, and the @test annotation is also from the package org.junit.Test

Simulate the environment where the problem code occurs: Maven project, with a main/Java/test01.Java and test/Java/test01.Java class

main/java/Test01.java

import org.junit.Test;

public class Test01 {
    @Test
    public void test01() {
        System.out.println("hello world - main/java/Test01.java");
    }
}

test/java/Test01.java

public class Test01 {
    public static void main(String[] args) {
        System.out.println("hello world - test/java/Test01.java");
    }
}

To solve the above problems, the following conditions must be met:

1.The same path. It means that the path of the class must be at the same level. If the test/java/Test01.javaand mian/java/Test01.javais the same level, the test/java/Test01.javaand mian/java/hello/Test01.javais not the same level , and there will be no conflict.
2.Same class name. Refer to the same class name in the same path as test/java/Test01.javathe main/java/Test01.javasame path and is both the name of the same class, test/java/Test02.javawith the main/java/Test01.javaconflict although the same path but different class name, it will not happen.
3.Use @Testcomments or not. In the case where the path and class name are the same, if main/java/Test01.javathere is an @Testannotated method in it, and test/java/Test01.javathere must be no @Testannotated method in it, this conflict will occur. If there is an @Testannotated method and the method name is different, it will be reported to use Junit Unit test error “No tests found matching Method test01(Test01) from ClassRequest@5387f9e0” .

After the above conditions are met, the above error will be reported by executing the test method with @test annotation under main/Java .

Solution:

Make their class paths different.

Make their class names different

Under test/Java, there must be methods using @test annotations

In short, it is recommended not to write test methods with @test comments under main/Java, let alone conflict them.

Kotlin gets the ID automatically error [How to Solve]

Use Android studio to automatically create a kotlin project. To automatically obtain the ID in the layout in the project, you need to follow the steps below

1. In the project build Add ‘kotlin Android extensions’ to gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

2. To modify the configuration of sourcecompatibility, the default studio is automatically created using kotlin_version

 compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

3. Find gradle.properties file in the root directory of the project, Add android.enableJetifier=true:

android.enableJetifier=true

All right! Then you can use it.
when using it, you need to import the layout file.
normally, press and hold act + enter to select import for automatic import, or you can add it manually. For example, the name of my layout file is activity_main.XML that is import kotlinx android.synthetic.main.activity_main.*

 import kotlinx.android.synthetic.main.activity_main.*

Error while Launching activity [How to Solve]

1. Use ADB to write in the package restart program ADB uninstall package name
if there is no ADB command:
(1) create a. Bash_profile file (input touch.Bash_profile)
(2) open the. Bash_profile file (input open – E.Bash_profile)
(3) edit in the open. Bash_profile file: export path = ${path} :/users/your own user name/library/Android/SDK/platform tools
after editing, save and exit
(4) execute the command source. Bash_profile;
(5) enter, and the ADB version will succeed if the version number appears. Finally, execute the ADB uninstall package name, output success, and restart the program

2 at manifest Does the XML declare two activities as launchers

3 in the listing, add your first startup class and filter code, copy the whole intent filter and add it to your first startup class

<activity android:name=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>