Android Studio: cannot resolve some symbol and method - android

I install the Android Studio and build a new project, but the automatic generated code show lots of "cannot resolve" errors like "cannot resolve symbol app" in the code "import android.support.v7.app.ActionBarActivity;"
The onCreate and setContentView Method cannot be resolved too
My Android Studio version is 0.4.2 , gradle version is 1.9
my build gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}

You can do "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.
Well that worked for me.

Open your SDK Manager (you can find it in toolbar), and download
Android Support Repository and Android Support Library (you can find them in extras).
Google Repository and Google Play Service
Then sync your project with your gradle files (there is a button in toolbar).

Related

Android Studio 2.3 failed find build tools

I'm getting mad, after updating android studio 2.2 to 2.3 i can't create and edit any project because gradle get error:
Failed to find build tools revision 26.0.0 or any versions
I downloaded Gradle and build tools from android studio also but didn't work.
My gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "atys.myapplication"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
and:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
}
You Should Update Your Tools with the SDK Manager First .
Look This Link Its Helpful.
https://developer.android.com/studio/intro/update.html
if your problem do not solve. uninstall your android studio and Delete you Sdk Folder and reinstall android studio new Version from this link:
https://developer.android.com/studio/index.html

Multiple errors during the gradle sync when I try to add Google Service library to the dependencies

I want to add to my app some ads using AdMob, the site says I need to add Google Services to the dependencies to use this functionality. So with Android Studio I went to File->Project Structure->app->Dependencies, I clicked on the "+" button e searched for "play-services". What I found was "com.google.android.gms:play-services:9.4.0" so I added it to the dependencies. During the gradle sync however Android Studio sends some errors and stops the gradle sync.
This is the log I get form the sync: http://pastebin.com/ZpN4RUcm
Here some data that might be useful:
Compile SDK Version: API 17
Build Tools Version: 23.0.1
Android
Studio 2.1.2
This is my main gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
And this is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:17'
buildToolsVersion '23.0.1'
defaultConfig {
applicationId "com.serpenssolida.glowdodger"
minSdkVersion 10
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:17.0.0'
compile files('libs/processing-core.jar')
compile project(':facebook')
compile 'com.google.android.gms:play-services:9.4.0'
}
How can I get rid of all the errors?
Change your app gradle file as below and try again:
apply plugin: 'com.android.application'
android {
compileSdkVersion '24'
buildToolsVersion '24.0.2'
...
}

Gradle failed to sync with 'unable to find optional library'

I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
From the google docs:
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
Top level build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project
After a lot of working this solutions work for me
.
** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.**
.
it will solve your issue.
In my case, it didn't work because I was missing optional.json in <sdk-path>\platforms\android-23\optional\, directory with the following content:
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Creating a new JSON file with with above content solved the problem for me.
You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.
Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`
To do this, just right click on your project and select Show in Explorer then go to ...\app\libs and paste above jar file and Sync your Project with Gradle File
Module:app
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "<ur_app_id>"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Update your project gradle file to use gradle version 1.3.1.
classpath 'com.android.tools.build:gradle:1.3.1'
Also try adding codehause repo.
repositories {
mavenCentral()
maven{
url 'http://repository.codehaus.org'
}
}
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to .../Android/Sdk/platforms/android-23 I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.
You should manually check that you have the same version of the SDK installed that is specified under compileSdkVersion in your build.gradle file.
To save time 2 solutions are best and works for me.
Solution 1 :
open your android sdk manager and reinstall API 23 (remove and install again).
Solution 2 :
Download this file which contain optional.json file
extract and move optional.json to :
C:\Users\\AppData\Local\Android\sdk\platforms\android-23\optional
if above solution is not work then try this way
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.
Copy "sdk\platforms\android-23\optional\org.apache.http.legacy.jar" to your app module libs directory, then add as library;
If you enable the proguard, please edit "proguard-rules.pro" to keep related classes or exception will occurred.

Gradle failed to refresh Android Studio

Ive been installing and re-installing AndroidStudio since i keep getting the error
> Gradle 'android' project refresh failed:
> Open quote is expected for attribute "{1}" associated with an element type "language".
All of my group members can open up the project without receiving this error except me.I am in dire need of help,i just want to finish my group project for the semester.Thank you for your help.
settings.gradle
include ':app'
build.gradle in the app folder
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.3.23'
compile 'com.android.support:support-v4:18.0.0'
files('libs/json-simple-1.1.1.jar')
compile files('libs/json-simple-1.1.1.jar')
}
build.gradle in the gradle folder
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Update:did another re-intstall of Android Studio and now its giving me this error.
Failed to refresh Gradle project 'android'
Out of memory: Java heap space. Configure Gradle memory settings using '-Xmx' JVM option (e.g. '-Xmx2048m'.)
Please fix the project's Gradle settings.
Gradle settings
You might have typed closed quote (“) instead of open quote("). Change the quotes at start and end of attribute.

Gradle can't find library

I am trying to include Otto library in my project, but am getting this error:
> Could not resolve all dependencies for configuration ':maptest:_debugCompile'.
> Could not find com.squareup:otto:1.3.4.
I have tried cleaning project, running Tools -> android -> sync project with gradle files but that gives me the same error.
My build.gradle is the following:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:19.0.1'
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.squareup:otto:1.3.4'
}
You should add maven central repository, so gradle know where so search for library.
repositories {
mavenCentral()
}
Did you import Otto library into Android Private Libraries? Try clean project this way: Project -> Clean...
You may check this out.

Categories

Resources