Tag Archives: android studio

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

The new Android studio (4.2) no longer supports the old one

com.android.tools.build:gradle:2.3.3

However, some methods and classes will not be found.

Go to build Change this classpath to the latest version in gradle. It’s best to update the versions of gradle and gradle wrapper. For example:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

As shown in the figure above, don’t forget Maven plus Google()

[Solved] Android Studio Compile Error: More than one file was found with OS independent path ‘lib/armeabi-v7a/libRSSupport.so’

It mainly refers to the problems that will occur when the functions related to ground glass are added and the project is dependent on multiple molds. The solution is also relatively simple. Here is a record

packagingOptions {  

pickFirst 'lib/armeabi-v7a/libRSSupport.so'  

pickFirst 'lib/x86_64/libRSSupport.so'  

pickFirst 'lib/x86/libRSSupport.so'  

pickFirst 'lib/arm64-v8a/libRSSupport.so'

 

pickFirst 'lib/x86_64/librsjni_androidx.so'  

pickFirst 'lib/x86/librsjni_androidx.so'  

pickFirst 'lib/arm64-v8a/librsjni_androidx.so'  

pickFirst 'lib/armeabi-v7a/librsjni_androidx.so'

 

pickFirst 'lib/x86/librsjni.so'  

pickFirst 'lib/arm64-v8a/librsjni.so'  

pickFirst 'lib/x86_64/librsjni.so'  

pickFirst 'lib/armeabi-v7a/librsjni.so'  

}

It’s good to filter the related LIBS, mainly these three. If there are other architecture adaptations, it’s good to add paths to the corresponding ones.

Android Studio Failed to Install app Error: INSTALL_FAILED_DUPLICATE_PERMISSION

When running the installation app in Android studio, if the installation fails, the following exception occurs:
installation did not succeed.
the application could not be installed: install_FAILED_DUPLICATE_PERMISSION

This indicates that the custom permission conflicts with the installed apps in the system, because two apps with different signatures are not allowed to define the same permission from Android 5.0
so the solution is to modify the permission definition, not the same as the existing app

Common error reports and handling methods of Android studio

Click Update on Android studio, and the system will be upgraded automatically. After Android studio is restarted automatically, the previous project gradle will be compiled normally:

 Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.4/userguide/gradle_daemon.html
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for object heap

Solution:

Upgrade the version:

Error Message:

C:\Users\Administrator\.AndroidStudio1.3\system\log\idea.log error:

2015-09-05 13:46:13,019 [ 724462] INFO – .BaseProjectImportErrorHandler – Failed to import Gradle project at ‘F:\java\Android\workspace\androidPracticeSpace\MyApplication’
org.gradle.tooling.GradleConnectionException: Could not run build action using Gradle installation ‘F:\Program Files\Android\Android Studio\gradle\gradle-2.4’.
at org.gradle.tooling.internal.consumer.ResultHandlerAdapter.onFailure(ResultHandlerAdapter.java:59)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:57)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
at org.gradle.tooling.internal.consumer.BlockingResultHandler.getResult(BlockingResultHandler.java:46)
at org.gradle.tooling.internal.consumer.DefaultBuildActionExecuter.run(DefaultBuildActionExecuter.java:46)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.doResolveProjectInfo(GradleProjectResolver.java:188)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.access$300(GradleProjectResolver.java:65)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:360)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver$ProjectConnectionDataNodeFunction.fun(GradleProjectResolver.java:332)
at org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper.execute(GradleExecutionHelper.java:215)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:97)
at org.jetbrains.plugins.gradle.service.project.GradleProjectResolver.resolveProjectInfo(GradleProjectResolver.java:65)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:41)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl$1.produce(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.AbstractRemoteExternalSystemService.execute(AbstractRemoteExternalSystemService.java:59)
at com.intellij.openapi.externalSystem.service.remote.RemoteExternalSystemProjectResolverImpl.resolveProjectInfo(RemoteExternalSystemProjectResolverImpl.java:37)
at com.intellij.openapi.externalSystem.service.remote.wrapper.ExternalSystemProjectResolverWrapper.resolveProjectInfo(ExternalSystemProjectResolverWrapper.java:49)
at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:51)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:138)
at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:124)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$4.execute(ExternalSystemUtil.java:540)
at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$5$2.run(ExternalSystemUtil.java:621)
at com.intellij.openapi.progress.impl.CoreProgressManager$TaskRunnable.run(CoreProgressManager.java:563)
at com.intellij.openapi.progress.impl.CoreProgressManager$2.run(CoreProgressManager.java:152)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:452)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:402)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:137)
at com.intellij.openapi.progress.impl.ProgressManagerImpl$1.run(ProgressManagerImpl.java:126)
at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:400)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)
at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)
Caused by: org.gradle.api.GradleException: Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.4/userguide/gradle_daemon.html
Please read the following process output to find out more:
———————–
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

 

at org.gradle.launcher.daemon.bootstrap.DaemonGreeter.parseDaemonOutput(DaemonGreeter.java:35)
at org.gradle.launcher.daemon.client.DefaultDaemonStarter.startProcess(DefaultDaemonStarter.java:113)
at org.gradle.launcher.daemon.client.DefaultDaemonStarter.startDaemon(DefaultDaemonStarter.java:94)
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.startDaemon(DefaultDaemonConnector.java:109)
at org.gradle.launcher.daemon.client.DefaultDaemonConnector.connect(DefaultDaemonConnector.java:87)
at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:117)
at org.gradle.launcher.daemon.client.DaemonClient.execute(DaemonClient.java:77)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:44)
at org.gradle.tooling.internal.provider.DaemonBuildActionExecuter.execute(DaemonBuildActionExecuter.java:31)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:62)
at org.gradle.tooling.internal.provider.LoggingBridgingBuildActionExecuter.execute(LoggingBridgingBuildActionExecuter.java:34)
at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:113)
at org.gradle.tooling.internal.provider.ProviderConnection.run(ProviderConnection.java:107)
at org.gradle.tooling.internal.provider.DefaultConnection.run(DefaultConnection.java:186)
at org.gradle.tooling.internal.consumer.connection.CancellableConsumerConnection$CancellableActionRunner.run(CancellableConsumerConnection.java:105)
at org.gradle.tooling.internal.consumer.connection.AbstractConsumerConnection.run(AbstractConsumerConnection.java:60)
at org.gradle.tooling.internal.consumer.DefaultBuildActionExecuter$1.run(DefaultBuildActionExecuter.java:57)
at org.gradle.tooling.internal.consumer.connection.LazyConsumerActionExecutor.run(LazyConsumerActionExecutor.java:83)
at org.gradle.tooling.internal.consumer.connection.ProgressLoggingConsumerActionExecutor.run(ProgressLoggingConsumerActionExecutor.java:58)
at org.gradle.tooling.internal.consumer.async.DefaultAsyncConsumerActionExecutor$1$1.run(DefaultAsyncConsumerActionExecutor.java:55)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:662)

 

[Solved] Android studio AAPT2 error: Execution failed for task ‘:app:mergeDebugResources’.

Error Message:

Error:Execution failed for task ‘:app:mergeDebugResources’.
Error: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details

Performance: cant resolve symbol R

Solution: Add a line of code to the project’s gradle.properties: android.enableAapt2=false and you’re good to go!

 

Error in creating a new class file for Android studio

Error in creating a new class file

After Baidu, the reason is: there is no class template

Solution: in file > settings> File and Code Templates> Add the following code to class:

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
 
#if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
#end
#parse("File Header.java")
 
#if (${VISIBILITY} == "PUBLIC")public #end #if (${ABSTRACT} == "TRUE")abstract #end #if (${FINAL} == "TRUE")final #end class ${NAME} #if (${SUPERCLASS} != "")extends ${SUPERCLASS} #end #if (${INTERFACES} != "")implements ${INTERFACES} #end {
}

 

Android studio reports an error using startservice: IllegalStateException

Android 8.0 starts the service with errors: java.lang.runtimeexception and java.lang.illegalstateexception

Error message:

 java.lang.RuntimeException: Unable to start receiver cn.edu.zut.broadservice.MyReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=cn.edu.zut.broadservice/.MyService }: app is in background uid UidRecord{b67c471 u0a86 RCVR idle change:uncached procs:1 seq(0,0,0)}
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3388)
        at android.app.ActivityThread.access$1200(ActivityThread.java:199)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=cn.edu.zut.broadservice/.MyService }: app is in background uid UidRecord{b67c471 u0a86 RCVR idle change:uncached procs:1 seq(0,0,0)}
        at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1577)
        at android.app.ContextImpl.startService(ContextImpl.java:1532)
        at android.content.ContextWrapper.startService(ContextWrapper.java:664)
        at android.content.ContextWrapper.startService(ContextWrapper.java:664)
        at cn.edu.zut.broadservice.MyReceiver.onReceive(MyReceiver.java:24)
        at android.app.ActivityThread.handleReceiver(ActivityThread.java:3379)
        at android.app.ActivityThread.access$1200(ActivityThread.java:199) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1661) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

Error reason:

If an application for Android 8.0 tries to use the startservice() function without allowing it to create a background service, the function will raise a IllegalStateException

The new context. Startforeroundservice() function will start a foreground service. Now, even if the application runs in the background, the system allows it to call context. Startforeroundservice() . However, the application must call the startforegroup() function of the service within five seconds after the service is created

For more information, see background execution restrictions

Solution:

In the place where the service was originally started, set startservice(); Replace with the following code

Intent intent = new Intent(context, MyService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    context.startForegroundService(intent);
} else {
   context.startService(intent);
}

And add it in the class of service (this content can be ignored if it runs normally after adding the above code)

@Override
public void onCreate() {
    super.onCreate();
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
       startForeground(1,new Notification()); 
}

Reference: reference address

Error reason for adding PNG pictures in Android studio

    Today, I saw an Android post about splash activity on the Internet. The blogger also gave the code after an explanation. So I decisively downloaded it to see how to achieve it. This function is implemented step by step according to the process. There are no major problems, but an error is prompted during gradle compilation:

libpng error: Not a PNG file

    From the prompt, it is very concise and clear. The added resources do not belong to PNG format. But I looked at the files in the resource folder. They all end in PNG format. After searching the Internet, I found a post on stackoverflow saying: don’t just look at the end of the file name *. PNG, but look at whether the actual format is PNG format. What do you think?There is a way to open the file directly with a hexadecimal editor to see if the first few characters are “. PNG”. As follows:

    In addition, there is a simple way to open these picture files one by one with the picture viewer, and then save them as PNG format files. This method, whether it is or not, is safe to save it again. Of course, the workload is also relatively handed over

    In the process of using PNG pictures, you may also encounter the following error prompts:

iccp:Not recognizing known sRGB profile that has been edited

The reason for this error is that the packaging tool AAPT in the higher version Android SDK has upgraded the libpng package. The toolkit has very strict requirements on the PNG format. Therefore, one solution is to reduce the compile SDK version and use the lower version SDK tool for compilation and packaging. Of course, there are other ways to solve this problem: use the image editing software to remove the metadata in the image:

ImageMagick

ImageOptim

 

[Solved] Android Studio Warning: Default Activity not found

1.AndroidManifest.xml

<activity
            android:name=".activity.StartPage"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

2.If that doesn’t solve the problem:

Delete all files in the following directory.

C:\Users\my_user_name\.AndroidStudio3.3\system\caches

View android studio version.

[Solved] Android Studio Compile error: Android resource linking failed

Problem description

Today when running the app through the emulator in Android studio, the following error occurred.

Android resource linking failed
AAPT: D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2781: error: resource android:attr/fontVariationSettings not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:2782: error: resource android:attr/ttcIndex not found.
D:\developer\androidproject\MyApplication\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3207: error: resource android:attr/textFontWeight not found.
error: failed linking references.

Warning: Android resource linking failed,error: failed linking references。

Troubleshooting

This is usually caused by the project configuration, open File-> Project Structure, and see the modules option as follows:


In the above figure, you will find that the compile sdk version and the build tools version are not the same, so change the build tools version to 26.
This is shown in the figure below:

Run again successfully.

Sometimes, after modifying the above configuration, you will still encounter the error “Android resource linking failed”, but if you look at the build information carefully, you may also encounter another error, as shown in the following marker.

The error reads:

The specified Android SDK Build Tools version (26.0.0) is ignored, as it is below the minimum supported version (29.0.2) for Android Gradle Plugin 4.0.1.

This involves the Android gradle plugin, the specific can refer to the official website, find the matching version.