Tag Archives: android development

Kotlin activity Startup and Compile Error [How to Solve]

The android project added an activity written in kotlin code and tried to launch the page.
The error is reported as follows:

C:\Users\15901\Desktop\ShangXueTang\app\src\main\java\com\example\shangxuetang\MainActivity.java:41: ����: �Ҳ�������
startActivity(new Intent(MainActivity.this, LifecycleActivity.class));
^
����: �� LifecycleActivity
�: �� MainActivity
1 ������

 

Solution:

    1. Add the following two lines of configuration to build.gradle(:app)
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
    1. add the dependency path.
dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }

Android Studio compile error: build tools is corrupt [Solved]

Error Messages:
Installed Build Tools revision 32.0.0 rc1 is corrupted. Remove and install again using the SDK Manager.
Problem Cause.
File corruption in buildTools after AndroidSutdio version upgrade.

Solution:
1 Modify d8.bat to dx.bat
2 Modify d8.jar to dx.jar

[Solved] Android gradle Error: gradle project sync failed. Please fix your project and try again

Another error was reported during Android development. This is a version error. The first step is to synchronize the versions
error message:
Android studio error: gradle project sync failed. Please fix your project and try again

1. Version synchronization:

1.1 file> sync project with android gradle

If you succeed, you don’t have to look at the following

1.2 error reporting:

It can be seen or not solved:

It should be the version problem. If we can’t download it, we can download it directly manually (check the network first, and the agent has no problem, but it still can’t be solved)

2. Modify proxy parameters:

Agent:

2.1 open file> setting> Search proxy

2.2 configuration information

The address and port of the agent shall be filled in as follows:

URL: http://127.0.0.1:1080/pac

2.3 check whether the Ping is connected

    1. use check connection

      1. enter a website to test: www.baidu.com, and then test: </ OL>

Still not!

3. Manual Download

So let’s continue:

3.1 open the gradle wrapper properties file

3.2 download

Download the gradle in the last line of the website. Note that the version must be consistent. Download whatever he puts down.

3.3 modifying environment variables

Remember to modify the gradle environment variable in the computer:

        1. system environment variable:

          1. path:

3.4 modify the compilation environment configuration

Then unzip it, modify the gradle configuration in the environment, and it’s OK.

You can see that my environment is OK now:

socket java.net.BindException: bind failed: EACCES (Permission denied)

It took a long time today to find out the real problem.

There are two situations most likely to cause the whole exception:

1. No permission is given;

a. Permission application is not added in androidmanifest.xml;

<uses-permission android:name="android.permission.INTERNET"/>

b. The format of permission application is incorrect

<!-- Mistake -->
<uses-permission android:name="android.permission.INTERNET"></uses-permission>

c. The permission is manually shielded by the user;

2. Port less than 1024; Set a larger one, not more than the largest one;

The application could not be installed: INSTALL_FAILED_USER_RESTRICTED

Android studio gives the following error after clicking “run app”

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_USER_RESTRICTED

List of apks:
[0] 'E:\MyProject\xxx\app\build\outputs\apk\debug\xxxxx_.apk'
Installation via USB is disabled.

Troubleshooting steps:

1. It may be that the USB installation is not enabled in the developer option. Check whether it is enabled and try again

2. It is possible that the application tag of androidmanifest.xml has been added

android:appComponentFactory=""
tools:replace="android:appComponentFactory"

Delete this attribute and try again.

[actual record of Android stepping on the pit] Android studio runs with errors. Installed build tools revision 31 is broken

The IDE advised me to reinstall the build tools. After many times of reinstallation, I still reported an error. Then I saw that there was an error in the version 30 of my brother online, and then it was reduced to 29. If I had passed the build, I reduced 31 to 30, and then it passed
obviously, the compatibility and stability of the new version are poor
in the Android of the global build.gradle,
change 31 to 30, as shown in the figure below.
resync and then build.

[actual record of Android stepping on the pit] Android studio reports an error invalid gradle JDK configuration found after importing the project

Encountered this problem, as a result, no blog is the right way to deal with it

Error reporting reason

Mismatched configuration files are generated after directly opening the project or importing the project with an incorrect JDK path

Solution

Delete the file with the suffix “. IML” under the. Idea path, and then set the correct JDK path. A JDK is available in the Android studio directory. Then file – & gt; Sync project with gradle files, the IDE will regenerate a matching configuration file and solve the problem.

Gradle:Using flatDir should be avoided because it doesn‘t support any meta-data formats.

app.gradle

Code snippet 1:

repositories {
    flatDir {
        dirs 'libs'
    }
}

Code snippet 2:

dependencies {
    classpath "com.android.tools.build:gradle:4.2.2"
}

After gradle is upgraded to 4.2.2, the following prompt message will appear during compilation. Delete & lt; Code snippet 1 & gt; The problem can be solved

Using flatDir should be avoided because it doesn’t support any meta-data formats.
Affected Modules: APP

Use the LIBS directory if necessary

        Add the following code to the project module.gradle

android {
    
    ...

    sourceSets {
        main {
            jniLibs.srcDirs = ['libs']
        }
    }
}

Problem solving.

MAC Adb Shell Error: -bash: adb: command not found, adb

When the MAC system uses ADB for the first time, it reports an error because it needs to configure tools,

When using the MAC for development, you use the ADB instruction to perform some operations. If you have not configured the Android environment variables, you will encounter the problem of ADB: command not found. You need to configure the Android environment variables on the Mac

Operation steps:

1. Open the terminal terminal of the Mac and enter Cd ~/[enter the home directory of the current user]
2. Enter touch. Bash_ Profile [if not. Bash_ Profile, create a file]
3. Enter open. Bash_ Open the file we created and a text edit box will pop up. If the environment is configured for the first time, the text edit box will be blank.
4 . export ANDROID_ HOME=/Users/haijunren/Library/Android/sdk
export PATH=${PATH}:${ANDROID_ HOME}/tools
export PATH=${PATH}:${ANDROID_ Home}/platform tools
note: Android in 4_ Home should be filled in according to its own SDK path, and the rest can be copied directly. As for the SDK path, you can open Android studio and search the SDK in preference (Windows setting) to view it
Enter source. Bash in the terminal_ Profile [make our changes effective]
Enter ADB [verify whether the configuration is complete, if the ADB: command not found is not displayed, the configuration is complete]

[Android] method of removing title bar and using request window feature (Window.FEATURE_ NO_ Title); why does it fail

Use RequestWindowFeature (window.feature_no_title) to hide the cause of the title bar failure.
might be an activity that inherits from AppCompatActivity.
Create an activity that inherits an activity. Create an activity that inherits an activity.
The first method is often used when getting started:

requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove the title bar Note that this sentence must be written in front of the setContentView() method, otherwise it will report an error

The second is defined in the AndroidManifest.xml file

<application android:theme="@android:style/Theme.NoTitleBar">

Wrote, then the application will remove the title bar, if just want to get rid of a certain Activity of the title bar, you can add this property to the Activity inside the tag
the third: this is not commonly used in general application, is in the res/values below to create a new style. The XML file

<?xml version="1.0" encoding="UTF-8" ?>
<resources>
    <style name="notitle">
        <item name="android:windowNoTitle">
            true
        </item>
    </style>
</resources>

In this way, we have a custom style, which is equivalent to a theme, and then define it in the AndroidManifest.xml file, which also removes the title bar

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name" 
    android:theme="@style/notitle">

Create an Activity that inherits AppCompatActivity by default

getSupportActionBar().hide();
//Remove the title bar Note that this sentence must be written after the setContentView() method

2 You can do the following configuration in AndroidManifest.xml so that there is no title bar

<application
   android:theme="@style/Theme.AppCompat.NoActionBar">

Android error reporting: error inflating class android.webkit.WebView

The project reported an unexplained error. However, I met this error three months ago, and it was only today that I got away with it.

First of all, what happened to this error

The layout file writes a WebView control, loads it in the activity, and then crashes! Only some lower version mobile phones can work normally.

Looking puzzled, I know one thing, there is no problem without reason, and there is nothing that can not be solved. But in the face of this, I gave up, because sometimes the project time is very tight, even Baidu for a long time can not solve the problem, had to keep the problem. I rebuilt a project.

Solution summary:

1. If you encounter this WebView rendering exception on Android o, add it under the application of manifest:

<meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
           android:value="true"/>

2. Error in loading WebView:

reason:

Non native app stores will prompt you to update “Android system WebView”. Update is good, that part of the mobile phone brush machine, Google’s own WebView package lost.

3. A foreign brother said (the problem has been solved)

I had same problem and i solved this problem by changing its theme in manifest.

Modify the theme of Applaction.

I changed any attribute in the theme, that is, a color attribute. After completing this topic and modifying, the project can run normally, and the crash problem disappears. My heart is still full of doubts.