Tag Archives: android studio

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.

Android Studio starts the emulator and appears “Timed out after 300seconds waiting for emulator to come online” solution

Problem: After the Gradle build is successful, the simulator fails to start. The specific performance is

1.Waiting for target device to come online

2.Timed out after 300seconds waiting for emulator to come online

 

solution:

1. Double check whether your Emulator is the latest version (SDK Manager–>SDK Tools–>Android Emulator) and update it to the latest version.

2. There is no problem with the above 1, double check whether the version of the emulator created by yourself complies with the “compileSdkVersion”, “buildToolsVersion” and other versions in gradle.

3. If there are no problems with 1 and 2 above, consider replacing an SDK, and then double check 1 and 2. (Works for me)

Android studio debug runtime ADB not responding

Programmer algorithm practice must read, common Java API skills to share>>>

Recently, my friend asked me about an Android studio debugging problem. I remember that I had encountered it before, so

Let’s write about it

ADB not responding.If you’d like to retry, then please manually kill “adb.exe” and click “restart”。

As shown in the figure:

This is because we have opened other applications or process services, which occupy the port number. These “pranks” are probably wandoujia of Peapod_ helper.exe,

Tadb.exe of Tencent or SJK of Jinshan_ Daemon.exe process and so on

Open the command prompt CMD (start menu search for “CMD”), enter ADB nodeamon server, enter, and remember the port number “5037”

PID: 5224 occupied

Then, press the shortcut key “Ctrl + Alt + Del”, or right-click the taskbar to open the task manager

Order bar “view” — “select column”, setting display PID

Then you can see the PID and find the PID used by the previous query port

For example: 5224, right click to end the process

Re open Android studio to connect your mobile phone or emulator

Android studio change project name exception solution: can’t rename root module

Programmer algorithm practice must read, common Java API skills to share>>>

When modifying the name of project in Android studio, prompt “can’t rename root module”

This is because Android studio can only modify all files in the root directory. To modify the name of the project root directory, you can only close Android studio and modify the folder name in the operating system

Specific steps:

1. Close Android studio

2. Modify the name directly in the operating system

3. Re import the project with a new name ([newname]), which is quite simple

In fact, after re importing, Android studio automatically modifies the name references in related projects, including the following two aspects:

1. Modify the. IML file name in the root directory to [newname]. IML, and fix the external. Linked. Project. Id = [newname] in the file

2. Modify & lt; in. Idea/modules. XML; module fileurl=”file://$PROJECT_ DIR$/[NewName].iml” filepath=”$PROJECT_ DIR$/[NewName].iml” />

Because these changes are automatically completed by Android studio, there is no need to modify them manually. This will change the name of the project