Tag Archives: Android

Execution failed for task ‘:app:kaptDebugKotlin‘ [How to Solve]

Error compiling project with kotlin:

Execution failed for task ‘:app:kaptDebugKotlin’.
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
java.lang.reflect.InvocationTargetException (no error message)
various kotlin annotation errors will be reported

The problem is that the version of kotlin plug-in is inconsistent with that in build

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

Check the version of the org.jetbrains.kotlin:kotlin-gradle-plugin is consistent with the version of the kotlin that the module depends on or not.

Android studio configurate intent-filter and compile error [Solved]

The error contents are as follows:

Manifest merger failed : android:exported needs to be explicitly specified for <activity>. 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.

 

When targeting is greater than or equal to Android 12, if some activities are configured with intent-filter, the exported property must be configured at the same time.

According to the error report, there are two solutions:

1. Modify the targetSdk of build.gradle less than 30.

2. Or add the export attribute to the <Intent-filter> tag in AndroidManifest.xml and assign it to true

Last hammer

No problem!

[Solved] adb Error: error: no devices/emulators found error: cannot connect to daemon

Scenario: Because the version using Jenkins file address phone can not download apk package, so can only be installed through adb to test the package. The phone model installed is Android: oopa57 Android system version 6.0.1.

The first thing is to use win + r to punch the Windows system command window, enter adb

Successful installation is shown in the figure above.

Confirm that the ADB installation is successful and enter ADB devices

The phone model is successfully identified as shown in the figure above.

Then enter

For example: adb install E:\***-***-2.0.0.1.apk

At this time, there will be an error prompt: the device cannot be found and cannot be installed

1: Check whether the developer mode of the mobile phone is turned on. Different mobile phones are turned on in different ways. Just Google

2: After opening, enter the loading command again

USB debugging is not turned on. As shown in step 1, the USB debugging at the bottom of the figure. Enter again after start

Note: during installation, the mobile phone will pop up to ask whether debugging is allowed, and click OK.

Then confirm that the installation is completed.

Note: Another case is that the data line is in poor contact with the USB interface. It is available when entering a command, but the next command fails. Pay attention to troubleshooting.

app:kaptDebugKotlin no error message [How to Solve]

Execution failed for task ‘:app:kaptDebugKotlin’.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)

 

Solution:
Run your application with ./gradlew clean build command to see what’s exactly wrong with your code. Just paste it into the Terminal in Android Studio.
Run gradlew clean build in Terminal to verify the compilation. If there are errors, the detailed code information will be listed here and then you can fix it.

How to Solve Android jetpack Room Schema export Error

1. When using the Android Room database, the following error occurs:

Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation annotation processor argument OR set exportSchema to false.

2. There are two kinds of solutions.
1). Set the exportSchema annotation to false for RoomDatabase. default is true

@Database(entities = [TableItem::class], version = 1,exportSchema = false)
abstract class AppDataBase : RoomDatabase() {
    abstract fun tableItemDao(): TableItemDao

2) Add in the build.gradle of the app (recommended)
There are different configuration syntaxes for java environment and kotlin environment. Depending on the personal environment configuration, only one way of writing can exist for both. My environment is a kotlin environment, so use the kotlin environment writing method. At the beginning, I used the java environment writing method, and the result kept reporting errors, and only after changing to kotlin did it work.

    defaultConfig {
        applicationId "XXX"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

        //Specify the path to the file generated by room.schemaLocation, java environment (choose one of the two, depending on the project environment)
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
            }
        }

        //Specify the path to the file generated by room.schemaLocation, kotlin environment (choose one of the two, depending on the project environment)
        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas")
            }
        }
    }

3. After configuration and compilation, JSON structure files of data will be generated in the following directory:

Kotlin develop Error: java.lang.VerifyError [How to Solve]

When using kotlin+ coroutine, compiling APK will throw Java lang.VerifyError: Verifier rejected class …

Cause: a supend method marked by a coroutine uses @JvmStatic annotation, resulting in a verify error when compiling and parsing code.

Solution: remove the annotation of the supend method.

Reference: https://stackoverflow.com/questions/59113152/java-lang-verifyerror-verifier-rejected-class-code-working-fine-in-debug-mode

[Solved] Startservice error: Process: com.example.provider, PID: 31612

Error Messages:

Process: com.example.provider, PID: 31612
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.provider/com.example.provider.MainActivity}: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.provider/.MyService }: app is in background uid UidRecord{9c06385 u0a69 TPSL idle change:idle|cached procs:1 seq(0,0,0)}
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
     Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.example.provider/.MyService }: app is in background uid UidRecord{9c06385 u0a69 TPSL idle change:idle|cached procs:1 seq(0,0,0)}
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1616)
        at android.app.ContextImpl.startService(ContextImpl.java:1571)
        at android.content.ContextWrapper.startService(ContextWrapper.java:669)
        at android.content.ContextWrapper.startService(ContextWrapper.java:669)
        at com.example.provider.MainActivity.onCreate(MainActivity.java:15)
        at android.app.Activity.performCreate(Activity.java:7817)
        at android.app.Activity.performCreate(Activity.java:7806)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)

 

Solution:

After Android 8.0, background processes are no longer allowed to start services directly through the startService method.:

startForegroundService

[Solved] Android Studio Compile Error: Execution failed for task ‘:APP_MIDI:lintVitalRelease‘.

1. Error reporting information

When compiling Android application, the following error is reported:

Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.

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

 

2. Solution

Method I

lint checks for errors, which are output in the build/reports/lint-results-release-fatal.xml file, and can be changed by changing the error message in the file to modify the syntax error;

Example of error message:

<?xml version="1.0" encoding="UTF-8"?>
<issues format="5" by="lint 4.1.0">

    <issue
        id="NotSibling"
        severity="Fatal"
        message="`@+id/button` is not a sibling in the same `RelativeLayout`"
        category="Correctness"
        priority="6"
        summary="Invalid Constraints"
        explanation="Layout constraints in a given `ConstraintLayout` or `RelativeLayout` should reference other views within the same relative layout (but not itself!)"
        errorLine1="        android:layout_below=&quot;@+id/button&quot;"
        errorLine2="        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
        <location
            file="D:\Application\app\src\main\res\layout\activity_main.xml"
            line="836"
            column="9"/>
    </issue>

</issues>

Method II:

Configure in build.gradle to remove lint checks:

android{
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
}

Android studio NDK setting is gray and cannot be solved

Android studio NDK is set to gray

After clicking File->Project Structure, the screen that opens cannot be configured with NDK localtion

The solution is to configure the ndk path directly in local.properties

My settings path:

sdk.dir=E\:\\thirdparty\\Android\\Sdk
ndk.dir=E\:\\thirdparty\\Android\\android-ndk-r21e-windows-x86_64\\android-ndk-r21e

Android Studio Cannot resolve symbol [How to Solve]

Problem:
Previously the project is normal, one day suddenly appeared red exception, the code is prompted in many places “Cannot resolve symbol xxxx” Log

Analysis:
The problem is caused by the failure of the three-party library dependency, the guide package can not be found

Solution (you can follow the following process to try):
1, Build->Clean Project and then Build->Rebuild Project to see if it is OK, not continue
2,File->Sync Project With Gradle Files to see if it’s OK, if not, continue
3,File->Invalidate Caches/Restart (check Clear Cache or Files) to see if it’s OK, or not.
4, close AS, manually enter the project to delete the .gradle and .idea files, reopen AS build to see if it is OK, not continue
5, downgrade the AS version, keep the settings and uninstall the current version, download and install the old version without problems before

The above five steps will basically solve the problem, which step is OK, just follow the order.
My problem is to the fifth step, from AS Bumblebee directly downgrade to AS4.2.1 before the problem is solved, the middle of the Arctic fox also have problems, specifically ignore.

Translated with www.DeepL.com/Translator (free version)

IDEA: How to Solve Springboot Project install Error

Found multiple occurrences of org.json.JSONObject on the class path:

    jar:file:/C:/Users/Administrator/.m2/repository/org/json/json/20160810/json-20160810.jar!/org/json/JSONObject.class
    jar:file:/C:/Users/Administrator/.m2/repository/com/vaadin/external/google/android-json/0.0.20131108.vaadin1/android-json-0.0.20131108.vaadin1.jar!/org/json/JSONObject.class

You may wish to exclude one of them to ensure predictable runtime behavior

Solution:

Add to pomz: com.vaadin.external.google dependency ignore can be

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
			<exclusions>
				<exclusion>
					<groupId>org.junit.vintage</groupId>
					<artifactId>junit-vintage-engine</artifactId>
				</exclusion>
				<exclusion>
					<groupId>com.vaadin.external.google</groupId>
					<artifactId>android-json</artifactId>
				</exclusion>
			</exclusions>
		</dependency>