Trouble opening new program in Android Studio - java

I recently downloaded Android Studio and attempted to open a new project. The code that is generated looks like this:
package com.example.trevo.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class GettingStarted extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_getting_started);
}
}
The tabs at the top of my screen (scr, main, java, com, example, trevo, myapplication, GettingStarted) are all underlined in red. Also the 'R' in the line setContentView(R.layout.activity_getting_started); is red and gets the error "cannot resolve symbol". When I try to run the program as written I get the following error.
C:\Users\trevo\Documents\Java4Android_Projects\MyApplication\app\src\main\res\layout\activity_getting_started.xml
Error:(13, 49) String types not allowed (at 'layout_constraintBottom_toBottomOf' with value 'parent').
Error:(14, 45) String types not allowed (at 'layout_constraintLeft_toLeftOf' with value 'parent').
Error:(15, 47) String types not allowed (at 'layout_constraintRight_toRightOf' with value 'parent').
Error:(16, 43) String types not allowed (at 'layout_constraintTop_toTopOf' with value 'parent').
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
Information:BUILD FAILED
Has anyone else had this problem with Android Studio? What can I do to remedy these errors?

This is a known bug in Android Studio, happened to my build too.
To resolve it, Clean Build the project and remove the import which has R in it, Android Studio will then import the correct R
This issue seems to be resolved in the latest 3.0 RC build

Related

after adding wallpaper manager package it showing :(

`
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\wallpaper_manager-1.0.10\android\src\main\java\com\mulgundkar\wallpaper_manager\WallpaperManagerPlugin.java:129: error: cannot find symbol
String assetLookupKey = FlutterLoader.getInstance().getLookupKeyForAsset(assetPath);
^
symbol: method getInstance()
location: class FlutterLoader
C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\wallpaper_manager-1.0.10\android\src\main\java\com\mulgundkar\wallpaper_manager\WallpaperManagerPlugin.java:152: error: cannot find symbol
String assetLookupKey = FlutterLoader.getInstance().getLookupKeyForAsset(assetPath);
^
symbol: method getInstance()
location: class FlutterLoader
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':wallpaper_manager:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
`
wallpaper_manager: any
When I add the package, the project gives an error.
There was no problem in the old versions of flutter, but the application does not work anymore, how should I proceed?
If you look at the current javadocs for FlutterLoader, it doesn't declare a getInstance() method anymore. The method was deprecated and then removed.
According to https://stackoverflow.com/a/64456438/139985, since Flutter 1.22 you need to get hold of a FlutterLoader instance using FlutterInjector:
import io.flutter.FlutterInjector;
...
FlutterLoader loader = FlutterInjector.instance().flutterLoader();
See also: What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?

can't work generate JavaDoc in Android Studio - Error "javadoc" finished with exit code 4

"C:\Program Files\Android\Android Studio1\jre\bin\javadoc.exe" -locale en -protected -splitindex -d "F:\Abdeaziz Daoud\Documents\PPC App" #C:\Users\Abdelaziz\AppData\Local\Temp\javadoc_args
Loading source file C:\Users\Abdelaziz\AndroidStudioProjects\PPCApp\app\src\main\java\com\hyperone\ppcapp\MainActivity.java...
Constructing Javadoc information...
C:\Users\Abdelaziz\AndroidStudioProjects\PPCApp\app\src\main\java\com\hyperone\ppcapp\MainActivity.java:4: error: package android.os does not exist
import android.os.Bundle;
^
C:\Users\Abdelaziz\AndroidStudioProjects\PPCApp\app\src\main\java\com\hyperone\ppcapp\MainActivity.java:9: error: cannot access ViewGroup
public class MainActivity extends AppCompatActivity {
^
class file for android.view.ViewGroup not found
javadoc: error - fatal error encountered: java.lang.NullPointerException
javadoc: error - Please file a bug against the javadoc tool via the Java bug reporting page
(http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com)
for duplicates. Include error messages and the following diagnostic in your report. Thank you.
java.lang.NullPointerException
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$MembersPhase.runPhase(TypeEnter.java:934)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.doCompleteEnvs(TypeEnter.java:282)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$MembersPhase.doCompleteEnvs(TypeEnter.java:877)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:251)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:266)
at jdk.compiler/com.sun.tools.javac.comp.TypeEnter.complete(TypeEnter.java:198)
at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:642)
at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1326)
at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:583)
at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:560)
at jdk.javadoc/jdk.javadoc.internal.tool.JavadocEnter.main(JavadocEnter.java:79)
at jdk.javadoc/jdk.javadoc.internal.tool.JavadocTool.getEnvironment(JavadocTool.java:206)
at jdk.javadoc/jdk.javadoc.internal.tool.Start.parseAndExecute(Start.java:576)
at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:432)
at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:345)
at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
4 errors
"javadoc" finished with exit code 4

import android.support.v4.app.ActivityCompat;

This is the error i am seeing when i add "simple_permissions" package. How can i fix this? I recently upgraded flutter and it used to work very well before the upgrade.
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:9: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:9: error: cannot find symbol
import android.support.v4.app.ActivityCompat;
symbol: class ActivityCompat
location: package android.support.v4.app
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:10: error: package android.support.v4.content does not exist
import android.support.v4.content.ContextCompat;
^
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:156: error: cannot find symbol
ActivityCompat.requestPermissions(activity, perm, 0);
^
symbol: variable ActivityCompat
location: class SimplePermissionsPlugin
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:163: error: cannot find symbol
return PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(activity, permission);
symbol: variable ContextCompat
location: class SimplePermissionsPlugin
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:171: error: cannot find symbol
if (ActivityCompat.shouldShowRequestPermissionRationale(registrar.activity(), permission)) {
^
symbol: variable ActivityCompat
location: class SimplePermissionsPlugin
/root/flutter/.pub-cache/hosted/pub.dartlang.org/simple_permissions-0.1.9/android/src/main/java/com/ethras/simplepermissions/SimplePermissionsPlugin.java:175: error: cannot find symbol
if (ActivityCompat.checkSelfPermission(registrar.context(), permission) == PackageManager.PERMISSION_GRANTED) {
^
symbol: variable ActivityCompat
location: class SimplePermissionsPlugin
6 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':simple_permissions:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
[!] Flutter tried to create the file `android/settings_aar.gradle`, but failed.
To manually update `settings.gradle`, follow these steps:
1. Copy `settings.gradle` as `settings_aar.gradle`
2. Remove the following code from `settings_aar.gradle`:
def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
Exception: Please create the file and run this command again.
Exited (sigterm)
I suggest you to check the package before using it.
It seems that simple_permissions is outdated and this package hasn't been updated since 2018 and its repository is gone from github, consider using other package like permission_handler.
Cheers.

error: package com.google.android.gms.games does not exist

My imports are :
import com.google.android.gms.games.Games;
import com.google.example.games.basegameutils.GameHelper;
I get this error in Android Studio
error: package com.google.android.gms.games does not exist
error: package com.google.example.games.basegameutils does not exist
Error:(87, 75) error: package GameHelper does not exist
Error:(116, 13) error: cannot find symbol class GameHelper
Error:(122, 28) error: cannot find symbol class GameHelper
Error:(230, 14) error: package Games does not exist
Error:(235, 14) error: package Games does not exist
Error:(242, 41) error: package Games does not exist
Error:(252, 41) error: package Games does not exist
Error:(259, 5) error: method does not override or implement a method from a supertype
Error:(263, 5) error: method does not override or implement a method from a supertype
>Error:Execution failed for task ':android:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
I have the BaseGameUtil imported as a module, and trying to integrate GPSS
I am also using Libgdx and updated the gradle to
include 'desktop', 'android', 'ios', 'core', 'BaseGameUtil'
So any ideas on what I did wrong?
You must import google-play-services_lib as a library of your project.
You can find this at the following path:
<your-android-sdk-directory</extras/google/google_play_services/libproject/google-play-services_lib
See this guide

Android Studio build file R broken

I am working on an android app which has worked and been tested many times. Today, however, in attempting to run the application for further testing, I have encountered the following error message:
C:\Users\1000\AndroidStudioProjects\WarofSol\app\build\generated\source\r\debug\com\blacktentdigital\warofsol\R.java
Error:(1251, 32) error: identifier expected
Error:(1251, 34) error: illegal start of type
Error:(1251, 35) error: identifier expected
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
>Information:BUILD FAILED
The problem is in the R.java file (as listed above). It is a generated file, so I've never touched it.
The offending line is this:
public static final class drawable {
public static final int 3=0x7f020000;
Hover over the offending line gives the following warning: "Identifier expected | Unexpected token"
Comparisons to other R files reveal that the "3" is not supposed to be a 3, and is evidently corrupted.
Attempts to replace the line or file with older backed-up versions have failed to produce any result because (evidently) the file is regenerating the wrong way each time I attempt the build, and I have no idea what might cause this. As I say, the problem sprang up suddenly without any provocation of which I am aware.
I've also attempted closing the program and restarting the computer to no avail.
Any ideas as to what might cause this and how it might be fixed?
I did get the Same error when i have defined a String in xml file like this.
<string name="3">Settings</string>
Error:
Error:(1426, 32) error: <identifier> expected
Error:(1426, 34) error: illegal start of type
Error:(1426, 35) error: <identifier> expected
Error:Execution failed for task ':app:compileDebugJava'.
> Compilation failed; see the compiler error output for details.
Information:BUILD FAILED
Solution: Resource name must begin with character.
So i have just change String like <string name="S3">Settings</string> and it worked.
So just check if you have any resource name 3 in all your resource file(string.xml, style.xml, attrs.xml) and folder(drawable, layout).
This is a quote from java documentation:
A variable's name can be any legal identifier — an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".
And you named drawable with digit, that caused the problem.

Categories

Resources