Tag Archives: Android studio

Android studio reported an error, Error:SSL peer shut down incorrectly

When we import projects with Android studio, we often encounter all kinds of errors, resulting in the project not running.

Recently, I have encountered a problem. What’s wrong Error:SSL peer shut down incorrectly

After checking, it seems that we have to change various configuration files, which is very troublesome.

I took a look at it right here

Compare with the local project that can be compiled normally, change the parameters.

Then it’s ready to run.

An error is reported after Android studio creates a new virtual machine. Emulator: emulator: error: unknown AVD name

Background: after Android studio is installed, a new virtual machine is created, and then it runs normally for the first time, and then it runs with two errors:
1. Emulator: emulator: error: unknown AVD name, use – list avds to see valid list.
2. Emulator: process finished with exit code 1
search the Internet for the problem, and find the following solution: save a note.
Original source: https://blog.csdn.net/xiaoxiao133/article/details/79819532
Abstract:
Open AVD manager, or you can find

in the menu bar tools, and then click Show on disk in the inverted triangle on the right

the picture is from the original blog Then jump to the folder of your virtual machine and copy the previous path. Take the original blog map as an example:
* * C: (users/administrator) \ *
just use the previous path (all the previous paths of Android include “\”)

and then go to Android in the computer environment variable_ SDK_ Under home

* add Android_ SDK_ The value of the home variable is changed to the path that was copied just now, C:: Restart Android studio!!
Thank you again for understanding Android_ SDK_ Environment variable of home!
Please contact me to delete it.

Android studio error Error:Could not Determine java version from ‘9.0.4’

The beginning of the matter is to export an APK with signature package and report an error Error:Execution failed for task ‘: app:compileReleaseJava ‘& gt; cannot find sys

At that time, my default setting location did not point to the correct JDK path, so an error was reported. Since I haven’t found my previous JDK for a long time, I went to the next version of JDK (9.0.4). Please pay attention to the latest version.

Then I try to export again and report an error: Error:Could not Determine java version from ‘9.0.4’

Then try again and continue to report errors Error:Gradle version 2.2 is required. Current version is 4.6. If using the gradle wrapper, try editing the distributionUrl in /Users//Desktop/gradle/wrapper/gradle- wrapper.properties to gradle-2.2- all.zip … because of the error caused by the inconsistency between the gradle version and the gradle version of as, modifying the gradle configuration file (there are many detailed solutions on the Internet) is of no use to me… Because after the change, an error is reported: could not initialize class com.android.repository . api.RepoManager Well, I gave up.

I began to think about why I encountered this series of problems at the beginning, right! Because of the latest version of JDK! So, I went to download a 1.8.0 JDK (download address), download and install it, change the JDK location of Android studio (Figure), and then gradle changed back to the old version, APK signature package export, success!!

So why should I download the latest JDK?:)

Writing to settings when appium of Xiaomi mobile phone and oppo mobile phone starts requires:android.permission.WRITE_ SECURE_ SETTINGS

Error information:
0 java.lang.SecurityException : Permission denial: writing to settings requires:android.permission.WRITE_ SECURE_ SETTINGS

terms of settlement:

Xiaomi: in the developer options, turn on “USB debugging (security settings)”. Allow USB debugging to modify permissions or simulate clicking

Oppo: in the developer option, turn on “disable permission monitoring”.
Copyright notice: This is the original article of CSDN blogger “revepon”, which follows the CC 4.0 by-sa copyright agreement. Please attach the link of the original source and this notice.
Link to the original text: https://blog.csdn.net/zzwfd/article/details/104005744

Error running app:Instant Run requires Tools | Android Enable ADB integration‘ to be enabled.

Error generation environment

The
is generated when running the project in Android studio

Error description

Error running app:Instant Run requires Tools | Android Enable ADB integration' to be enabled.

Cause of error

The project can be started normally before, but it can’t be started after Android studio upgrade

terms of settlement

In the options bar, click Tools – & gt; Android – & gt; enable ADB integration


after modification, it is as follows:
there is a tick in front of enable ADB integration.

java.lang.IllegalStateException: Could not execute method for android:onClick

I didn’t think about it before I heard it..

Error screenshot

error message

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.imoocmusicdemo, PID: 14631
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at android.view.View$DeclaredOnClickListener.onClick(View.java:5634)
        at android.view.View.performClick(View.java:6597)
        at android.view.View.performClickInternal(View.java:6574)
        at android.view.View.access$3100(View.java:778)
        at android.view.View$PerformClick.run(View.java:25885)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        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.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at android.view.View$DeclaredOnClickListener.onClick(View.java:5629)
        at android.view.View.performClick(View.java:6597) 
        at android.view.View.performClickInternal(View.java:6574) 
        at android.view.View.access$3100(View.java:778) 
        at android.view.View$PerformClick.run(View.java:25885) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        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: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.imoocmusicdemo/com.example.imoocmusicdemo.activitys.RegisterActivity}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2005)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1673)
        at android.app.Activity.startActivityForResult(Activity.java:4586)
        at android.app.Activity.startActivityForResult(Activity.java:4544)
        at android.app.Activity.startActivity(Activity.java:4905)
        at android.app.Activity.startActivity(Activity.java:4873)
        at com.example.imoocmusicdemo.activitys.LoginActivity.onRegisterClick(LoginActivity.java:40)
        at java.lang.reflect.Method.invoke(Native Method) 
        at android.view.View$DeclaredOnClickListener.onClick(View.java:5629) 
        at android.view.View.performClick(View.java:6597) 
        at android.view.View.performClickInternal(View.java:6574) 
        at android.view.View.access$3100(View.java:778) 
        at android.view.View$PerformClick.run(View.java:25885) 
        at android.os.Handler.handleCallback(Handler.java:873) 
        at android.os.Handler.dispatchMessage(Handler.java:99) 
        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) 
I/Process: Sending signal. PID: 14631 SIG: 9
Application terminated.

Cause of error

Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.imoocmusicdemo/com.example.imoocmusicdemo.activitys.RegisterActivity}; have you declared this activity in your AndroidManifest.xml?

resolvent: AndroidManifest.xml Add registeractivity

Android studio view System.out.print Content of

System.out.print Where is the content of ()?

Here is an example to illustrate:

First of all, it is recommended to use the println () method, because this method has its own line feed, which seems very convenient.

With System.out.println (“list:”+ list.get (0)); for example

When the application runs here on the device, check the printout in logcat. As shown in the figure:

Android Studio could not resolve resource

Refer here: http://blog.csdn.net/dong19870625/article/details/50833433

Original text:

In the development project, the XML file suddenly appears
couldn’t resolve resource @ color / title_ The color (58 similar errors not show) problem caught people off guard. It’s no problem to write the color and other resource files directly, but it’s not the fundamental solution to the problem

Android Studio just gets crazy. But a restart ain’t always enough.

Invalidate your caches and restart.

File -> Invalidate Caches / Restart… -> Invalidate and Restart

According to the above practice, the effect is good, solved my problem, the original as itself also has cache

reference resources: http://stackoverflow.com/questions/8390733/relativelayout-couldnt-resolve-resource-android

———————————————

I also met similar, but I can’t find the relevant style. It can’t be displayed normally in the preview, but it runs normally. No matter refresh or rebuild, it can’t be eliminated. Just follow the above procedure

Android:Field can be converted to a local varible.

background

It’s been a while since Android studio was used to develop Android. Occasionally, as has a yellow highlight on some private variables field can be converted to a local variable . I still don’t want to see this yellow highlight for some obsessive-compulsive disorder. Baidu did not find any useful information, or Google search to find some answers.

analysis

The complete description of field can be converted to a local variable is (hand play only): field can be converted to a local variable :

This inspection searches for redundant class fields that can be replaced with local variables,if all local usages of a field are preceded by assignments to that field,the field can be removed and its usages replaced with local variables.

This means that it is detected that this variable can be replaced by a local variable. It is recommended to delete it and write it as a local variable.

Solution

Delete the sentence private XXX; and declare and instantiate it directly where it is used.
In Android studio for Mac , you can use the shortcut key Alt + enter to quickly convert local variables.

PS: you still need better English. In fact, you can understand it by reading the instructions. You don’t need to search in this way.

Request window feature for Android Development( Window.FEATURE_ NO_ Title) does not take effect

What if you want to hide the ActionBar but the requestWindowFeature(window.feature_no_title) doesn’t work?
Reason: because they define the Activity of inherited android. Support. V7. App. AppCompatActivity, AppCompatActivity itself does not support requestWindowFeature (Window. FEATURE_NO_TITLE) cause, can change to inherit the Activity.

Android appears java.lang.NoClassDefFoundError A solution to the error

A few days ago, at the time of reconstructing an Android project, joined the RXJava , RxAndroid , Retrofit to support development response type, and refactor the code, refactoring everything but in running an Java lang. NoClassDefFoundError this error, and in a few test machine shows the name of the class is different also, For example, on MI4, there is no Handler, and on Huawei, there is no OKHttputils class. This is very confusing. After searching Google, we can't find the problem, but on another Samsung test machine, there is no problem, and finally we find that Multidex is the problem.
Some third party libraries were added during the refactoring, which pushed the number of methods in the entire Android application beyond 65535. The following error should occur when packaging

java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:282)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)

multiDexEnabled true z multiDexEnabled true defaultConfig z multiDexEnabled true Automatically when a method is more than 65535 hit two Dex package named classes. Dex classes2. Dex , some methods were scored the second Dex package, namely the classes2. Dex , resulted in 5.0 the following models can't run the error.
Here's the solution:
1. defaultConfigcode> m>dexEnabled true
is used>enable MultiDex
2. is added in the dependence on the compile 'com. Android. Support: multidex: 1.0.1' support package for 5.0 the following systems
3. If your project already contains the Application class, then let it inherits. Android support. Multidex. MultiDexApplication class, if your Application has inherited the other classes and do not want to do change, so there's another way of using, overwrite attachBaseContext () method:

public class MyApplication extends FooApplication {
        @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Some problems encountered by Android Aidl

Some problems with Android AIDL
(1) Starting Service ** is required after 5.0
An error will be reported if the service is started implicitly (unless Intent. SetPackage (” application package name of the service to be started “) is started implicitly).
Error:(9, 41) No symbol can be found
The reason is that the other class name (Java) file is mixed with aidl’s aidl file in the same directory
Java files have to be placed under the Java file (server package name + Java file).
Error 1
Error: Error converting the bytecode to dex:
Cause: Java. Lang. RuntimeException: Exception parsing classes
Reason package names contain uppercase letters

example:
er.java
p>ge com.example.lqm;
user.java
package com.example.lqm;
public class User implements Parcelable{
private String id;
privte String name;
… .
}
The corresponding aidl file is
user.aidl
package com.example.lqm; // This is user. aidl package
parcelable User;