Gradle unable to rebuild in android studio - android-studio

So i am still new to android studio and after finishing a test project,i kept getting errors about the gradle build and i dont understand what to do
startup failed:
build file 'C:\Users\*******\AndroidStudioProjects\Provac\build.gradle': 1: unexpected token: < # line 1, column 1.
<?xml version="1.0" encoding="utf-8"?>
^
1 error
The actual build.gradle file:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"/>

The problem is that your build.gradle file has been overwritten by an unrelated XML file, either due to human error or a bug in some piece of software.
If you have a backup or an earlier version of your code from version control, you should restore from it. Otherwise, you'll need to recreate your build.gradle file manually. The build.gradle file created by the Android Studio new project wizard is probably a good start, if you have to do that.

Related

How to embed android emulator inside Android Studio?

I know that an embedded emulator has been introduced in Android Studio 4.1+. I am not able to see options to enable it.
The changelog says that you need to enable it manually. Follow these steps:
Steps
Open Android Studio and goto Preference / Settings
Expand the Tools tab and goto emulator
Check 'Launch in a tool window'
Apart from the previous, if you dont't see the emulator tab in IDE:
I found that adding a "<module fileurl="file://$PROJECT_DIR$/android/..." line in Project directory, file .idea/modules.xml the tab appears:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/renal_calc_flutter.iml" filepath="$PROJECT_DIR$/renal_calc_flutter.iml" />
<module fileurl="file://$PROJECT_DIR$/android/renal_calc_flutter_android.iml" filepath="$PROJECT_DIR$/android/renal_calc_flutter_android.iml" />
</modules>
</component>
</project>

Error initializing ADB: Debug Bridge not found

I want to work with some files in flutter and so I wanted to use the Android Studio Device File Explorer to check if everything works correctly.
But the Device File Explorer shows a red warning "Error initializing ADB: Android Debug Bridge not found"
On a "normal" Android Project with Java there is no Problem and everything is displayed correctly.
I reinstalled Android Studio, changed the AVD but nothing changed.
Is this a bug in Flutter or Android Studio?
Thanks for helping.
Ok, I solved the problem. You must go to your Project Structure, add a Project SDK to your project and reopen Android Studio. Then the Problem should be solved.
The error might occur when you create a Flutter app in VS Code instead of Android Studio. To fix it, simply add a misc.xml file in your .idea folder, with the following contents or similar:
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_12" default="false" project-jdk-name="Android API 29 Platform" project-jdk-type="Android SDK" />
<component name="ProjectType">
<option name="id" value="io.flutter" />
</component>
</project>
You could also create a new Flutter project in Android Studio to view the contents of misc.xml as it might differ slightly.

Getting Error in style.xml file in android studio.Can not resolve symbol theme.Validates resource references inside Android XML files

The Application build and run correctly and there is no error in gradle build but the style.xml shows error.
I am using android studio 3.1 gradle version 4.4
Please see The Image.
from the top menu File -> Close project.
Remove it from the projects list.
Open existing project -> choose the project folder.

How can I fix "Design editor is unavailable until a successful build" error?

I started to learn Android Studio. I try to echo out simple "Hello World":
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:paddingBottom="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
but when I clicked "design" view, this error is showing?
Design editor is unavailable until a successful build
How can I fix this error.
I just noticed that my xml code is causing error. Is that why this may be not working?
Go to File > Sync Project with Gradles Files.
Quit the Android Studio ( not close the project Quit the Android Studio) then open the project and go to Android Studio > Build > Clean Project
Then
Android Studio > File > Sync Project with Gradles Files as the pic below
If your problem still exists then click the Install build tool as the pic below and then
Android Studio > File > Sync Project with Gradles Files
None of the above worked for me. what worked for me is to go to File -> Invalidate Caches / Restart
I faced same issue even after rebuilding my project multiple times successfully. I closed the project and re-opened, issue resolved.
First, find your build.gradle in your all modules in project, include app/build.gradle. Find the compileSdkVersion inside android tag, in this case, compile sdk version is 30:
Next, open SDK Manager > SDK Platforms, check for install SDK versions that there modules using, then apply to install selected platforms.
After installed, go to menu File > Sync project with Gradle files....
This issue often appear when project has many modules, each module use different compile SDK version, so app may be able to build but IDE have some issue while processing your resources.
Simply restart the Android Studio. In my case, I was offline before starting the Android Studio, but online when I did restart.
Do this
Build -> Rebuild Project
Install missing plataform and sync project
Go online before starting android studio. Then go file->New project
Follow onscreen steps. Then wait It will download the necessary files over internet. And that should fix it.
I got this problem after i added a line in my build.gradle file.
compile 'com.balysv:material-ripple:1.0.2'
Solution:
I changed this line to
implementation 'com.balysv:material-ripple:1.0.2'
and then pressed sync again.
Tada! all was working again.
In my case, it was because it didn't like that I left the minSDK and targeSdk in the manifest. Go figure.
just click file in your android studio
then click Sync Project with Gradle Files..
if it won't work,
click Build
click Clean Project.
it always work for me
The Android SDK Platform API Level that the project requires for targetSdkVersion may not exist.
Check the console of the Event Log tab of the IDE to see any errors eg. of the following type:
Gradle sync failed:
com.android.tools.idea.gradle.project.sync.idea.issues.SdkPlatformNotFoundException:
Module: 'common' platform 'android-29' not found.
Then install some API Level (29) in SDK Manager -> SDK Platforms and finally Sync again.
Edit you xml file in Notepad++ and build it again. It's work for me
I have the latest Android Studio 3.6.1 and yet couldn't build a simple 'Hello World' app as documented here "https://codelabs.developers.google.com/codelabs/android-training-hello-world/index.html?index=..%2F..%2Fandroid-training#3".
I applied various steps discussed above including the 2 most viable options which should have really solved this issue,
'File->Sync Project with Gradle Files' and
'File->Invalidate Caches/Restart' but to no avail.
Even though, I suspect standard answer should be one of these 2 options only for most, but for me the resolution came only after I went inside the 'File->Project Structure' and checked my SDK versions configured!
Android Studio and Gradle were using different JDK versions and locations.
Android Studio: C:\Program Files\Java\jdk1.8.0_241
Gradle: C:\Program Files\Java\jdk-13.0.2
I had previously defined my JAVA_HOME environment variable by downloading latest JAVA SDK on my own from ORACLE website. Where Gradle was using the %JAVA_HOME% JAVA SDK version and Android Studio the built in SDK which came along with Android Studio.
Once I switched both to versions JDK 1.8.* (Any version as long as it is JDK 1.8. for that matter*) then simple 'File->Synch...' option worked perfectly fine for me!
Good luck the solution is in between one of these 2 options only if you are stuck, just ensure you validate JDK versions being referred to!
there are different solutions to this problem but I at the first u have to check to (build.gradle) maybe it empty. this especially if u downloaded code, not u created
and u will find just this line "// Top-level build file where you can add configuration options common to all sub-projects/modules."
in this case, u need to open a new project and make copy-paste.then check the SDK and other settings.finally u have to sync
In my case, the Windows Firewall was blocking Android Studio (i.e. java.exe from Android Studio's jre/bin folder) from connecting to sites and downloading data. After Windows asked me if I wanted to allow the app through the firewall, I had to do a manual sync File -> Sync project with gradle files. After that, things were still disfunctional, a manual download of an SDK version 28 was necessary from Tools -> SDK Manager.
If you are in corporate setting where there is a proxy server, double check your proxy settings.
Go File -> Settings
Search for Proxy.
Fill out as appropreate.
Test connection.
If you think you fat-fingered the password, there is a Clear passwords button you can click to where you can re-enter your creds. HTH
I had tried to change SDK Version:
Check below image: In that I changed 27 from Android P

Run Butterknife samples on Android Studio

I try to run Butterknife project samples on Android studio 1.2 and keep getting that issue :
"Error:Android Source Generator: [butterknife-sample] AndroidManifest.xml file not found"
If I try to run the SimpleActivity, same issue : AndroidManifest.xml doesn't exist or has incorrect root tag.
Any idea

Resources