Tag Archives: Android

[Solved] JNI Error: ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

1. Error description

ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

What went wrong:
Execution failed for task ‘:app:externalNativeBuildDebug’.

Build command failed.
Error while executing process D:\ProgramFiles\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments

2. Cause of error

When developing JNI, this error occurs during compilation. It may be that the path of NDK is not set

3. Solutions

Add the path to the NDK in local.properties in the project directory
eg:

ndk.dir=D\:\\ProgramFiles\\Android\\sdk\\ndk\\21.3.6528147

Ubuntu18.04 Compile Error: android 7 FAILED [How to Solve]

Upgrade to Ubuntu 18.04. Compilation error. Make a backup.

The error message is as follows

FAILED: /bin/bash -c "prebuilts/misc/linux-x86/flex/flex-2.5.39 -oout/target/product/bullhead/obj/STATIC_LIBRARIES/libedify_intermediates/lexer.cpp bootable/recovery/edify/lexer.ll"
flex-2.5.39: loadlocale.c:130:_nl_intern_locale_data: ??'cnt < (sizeof (_nl_value_type_LC_TIME)/sizeof (_nl_value_type_LC_TIME[0]))' ???
Aborted (core dumped)

Solution:

Adding export LC_ALL=C before compiling will solve the problem.

Android Phone Record Screen Error: failed to get surface

As long as it is recorded on the screen, it is difficult to report errors. The common causes and solutions are summarized as follows:

1. Determine the storage permission. Note that Android 10, 11, 12, etc. the storage permission policy of Android has changed. Set the output path to ensure that it is under the path with read-write permission

File file=new File(getExternalFilesDir("")+"/Ansen_");
if(!file.exists()){
    file.mkdirs();
}
//Set the video output path
mMediaRecorder.setOutputFile(file.getAbsolutePath() + "/Ansen_" + curTime + ".mp4");

2. Correctly set the size of the recording screen, here note that this size is not necessarily the screen size, through the following method is not necessarily the same as the actual resolution, such as a plus phone, originally 1920 * 1080, in fact, through the following measurement results are not, this will require developers to get through the Camera.

 //Set the video size
 mMediaRecorder.setVideoSize(ScreenUtils.getScreenWidth(this), ScreenUtils.getScreenHeight(this));

Conventional method for obtaining the size of mobile phone (not necessarily accurate, inconsistent with the recording screen):

    /**
     * Get the width of the screen px
     */
    public static int getScreenWidth(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    /**
     * Get the width of the screen px
     */
    public static int getScreenHeight(Context context) {
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

To get the resolution supported by the camera, just select a group from the following.

        Camera camera = Camera.open();
        Parameters parameters = camera.getParameters();
        List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();

        for (int i = 0; i < supportedPreviewSizes.size(); i++) {
            supportedPreviewSizes.get(i).width;
            supportedPreviewSizes.get(i).height;
        }
        List<Size> supportedPictureSizes = parameters.getSupportedPictureSizes();
        for (int i = 0; i < supportedPictureSizes.size(); i++) {
            supportedPictureSizes.get(i).widt;
            supportedPictureSizes.get(i).height;
        }

3. Determine the setting sequence, which will affect

setAudioSource()

setVideoSource()

setOutputFormat()

setAudioEncoder()

setVideoEncoder()

setVideoSize()

setVideoFrameRate()

setOutputFile()

setVideoEncodingBitRate()

prepare()

start()

[Solved] Execution failed for task ‘:app:checkDebugAarMetadata‘

After updating Fuller, the following problems will be reported:

FAILURE: Build failed with an exception.

* What went wrong:
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.window:window-java:1.0.0-beta04.
        AAR metadata file: C:\Users\liqiang\.gradle\caches\transforms-2\files-2.1\9f515ee58db509b5f4759e97c8eb6aa2\jetified-window-java-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
   > 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.window:window:1.0.0-beta04.
        AAR metadata file: C:\Users\liqiang\.gradle\caches\transforms-2\files-2.1\a909ff21160c236fa8213aba5c707997\jetified-window-1.0.0-beta04\META-INF\com\android\build\gradle\aar-metadata.properties.
* 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.

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

BUILD FAILED in 4s
Exception: Gradle task assembleDebug failed with exit code 1

According to the error message The minCompileSdk (31) specified, the final sdk needs to be version 31, but our current sdk version is 30, which is greater than this version, so we need to modify the following configuration to 31

android {
    compileSdkVersion 31

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        /*configurations.all {
            resolutionStrategy { force 'androidx.core:core-ktx:1.6.0' }
        }*/
        applicationId "cn.liginfo.kqjhq_app"
        minSdkVersion 16
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

After modification, because there is no version 31 sdk, it will download automatically, but after downloading, the following error message appears again

Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/0dd39ff9faeeb501ffb52162e269003e/jetified-kotlin-stdlib-1.5.31.jar!/META-INF/kotlin-stdlib.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/2ea246a87a592f122121cfd0846ffbea/jetified-kotlin-stdlib-jdk7-1.5.30.jar!/META-INF/kotlin-stdlib-jdk7.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/9234cfcee40ec23fc2213363e9726513/jetified-window-1.0.0-beta04-api.jar!/META-INF/window_release.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/9af1d6ff9000d18681a83cd875960957/jetified-kotlinx-coroutines-core-jvm-1.5.2.jar!/META-INF/kotlinx-coroutines-core.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/b0b1eecff74e71ed1ef092403ad1018c/jetified-kotlin-stdlib-common-1.5.31.jar!/META-INF/kotlin-stdlib-common.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/d91778f7878bf943ae593906c9fd7c75/jetified-kotlin-stdlib-jdk8-1.5.30.jar!/META-INF/kotlin-stdlib-jdk8.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/df6880e9350e429186aa0973bbf49093/jetified-window-java-1.0.0-beta04-api.jar!/META-INF/window-java_release.kotlin_module: 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.
e: C:/Users/liqiang/.gradle/caches/transforms-2/files-2.1/e484fc5cda5fe73d156ca3b50e47d38e/jetified-kotlinx-coroutines-android-1.5.2.jar!/META-INF/kotlinx-coroutines-android.kotlin_module: 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.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* 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.

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

BUILD FAILED in 7s

┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                       │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle:                   │
│ ext.kotlin_version = '<latest-version>'                                                      │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
Exception: Gradle task assembleDebug failed with exit code 1

From the error message, it is said that the version of kotlin is wrong, and a specific solution is given

Your project requires a newer version of the Kotlin Gradle plugin.                       │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle:                   │
│ ext.kotlin_version = '<latest-version>'   

You need an up-to-date plugin named kotlin gradle, Find the recent version in https://kotlinlang.org/docs/gradle.html#plugin-and-versions and update the the latest-version value in ext.kotlin_version = ‘’ of the D:\javadeveloping\Android\workspace\kqjhq_app\android\build.gradle file.

after opening the web page, we found that the latest version is 1.6.10, while our previous version is 1.3.5:

just change to 1.6.10 and package normally

[Solved] Manifest merger failed with multiple errors, see logs

Adding a dependent library is an error when running, because the current project version is lower than the minimum trial version of the third-party dependent library

1. As shown in the current project’s build.gradle without setting the buildToolsVersion.

2. Set minSdkVersion to the minimum version of the dependency library in the current project’s build.gradle as shown here.

[Solved] AndroidStudio libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined referen

1. Error reporting:

The error of Android C + + OpenSSL link is as follows:

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigfillset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

I:/webrtc/android/openssl-1.1.1k/output-armeabi-v7a/lib/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'

clang++: error: linker command failed with exit code 1 (use -v to see invocation)

2. Reason:

Sigdelset, sigfillset and signal cannot be found in the SDK of Android

3. Solution:

Modify the minSdkVersion of build.grandle to a version number after 21:

apply plugin: 'com.android.application'
def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/webrtc_m84_20201001/webrtc_android/src/"
//def LIBWEBRTC_HOME_PATH = "I:/webrtc/android/androidnativeapi/app/webrtc/"
android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "org.webrtc.examples.androidnativeapi"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                arguments "-DLIBWEBRTC_HOME_PATH=" + LIBWEBRTC_HOME_PATH,
                        "-DANDROID_STL=c++_static"
            }
        }
        ndk {
            abiFilters  "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    sourceSets {
        main {
            // 1. configure the root directory libs to load third-party so libraries, (it is best not to create jniLibs, in the many open source libraries may cause conflicts, not yet found)
            // 2. automatically copy the so libraries in the libs directory to the specified directory when running
            // 3. If you don't need to recompile the so you created, you can copy the so generated by (app/build/intermediates/transforms) to this directory
            jniLibs.srcDirs = ['libs']
            // If it is a single folder, you can directly configure it as follows
            // jniLibs.srcDir 'libs'
        }
    }
    buildToolsVersion '28.0.2'//ADD
}
repositories {
    flatDir{
        dirs'libs'
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.aar"])

    //implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //implementation(name: 'libwebrtc', ext: 'aar')
    //implementation 'org.webrtc:google-webrtc:1.0.+'
}

[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] Android Kotlin Package release Error: Lint found fatal errors while assembling a release target.

preface

Recently, I wrote in kotlin that I was playing
and reported an exception in the packaged version of release

Lint found fatal errors while assembling a release target.
unable to read PNG signature: file does not start with PNG signature.

Solution:

 release {
            //Add
            lintOptions {
                checkReleaseBuilds false
                abortOnError false
            }
          }  


Outcome:
1.
2.