How to use Google Play Services 7.3.0 on AndroidStudio? - android

I've updated my Android SDK and also the PlayServices Library. Nothing seems to work right now.
The import com.google.android.*; does not exists, and I've added the 'compile' lines on the Gradle File.
Have someone experienced this? How can I solve this?
EDIT
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.google.code.gson:gson:2.3'
compile 'org.roboguice:roboguice:3.0.1'
compile 'com.google.android.gms:play-services:7.3.0'
}
That's the Gradle File for a Module.

If you use Android Studio and want to use the latest Google libraries via Gradle dependency, you will have to update the
You can do this via Tools -> Android -> SDK Manager -> You have to update the stuff under Extras
Also make sure that you are not using the Offline Mode of Gradle. You can find this option via (I did this on a Mac) Android Studio -> Preferences -> Gradle -> (Global Gradle Settings) Offline Work
Make sure this option is not checked.
Something which was mentioned by #CommonsWare already (and i add it just to sum up this answer) is to sync the project via the Gradle files. You can do this via the toolbar as seen here:
Or via the menu Tools > Android > Sync Project with Gradle Files
If nothing of the above is working for you, it would be really helpful if you can try to build the project via the command line or the terminal with the following command:
gradle clean build --debug
and then post the output here. It will hopefully show why it can't resolve the library.

Try Tools > Android > Sync Project with Gradle Files and see if that clears up your problem. There's a bug where Android Studio does not always warn you to do this with the yellow banner on the editor.

Related

Gradle build error of app after Android Studio 4.1 update

I have updated from Android Studio 4.0 to 4.1. After the update I cannot build my application anymore which worked fine before the update.
When I build the project I am getting the following exception:
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compressDebugAssets'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CompressAssetsWorkAction
my\application\path\app\build\intermediates\merged_assets\debug\out
The folder my\application\path\app\build\intermediates\merged_assets\debug\out is empty.
What I tried to do:
Clean and rebuild the project
delete the .gradle and the build folder and clean an rebuild the project
invalidate and restart Android studio
Increased the heap size in gradle.properties to: org.gradle.jvmargs=-Xmx4096m
Increased the compileSdkVersion and targetSdkVersion
Installed and updated the buildToolsVersion from 30.0.0 to 30.0.2
Added multiDexEnabled true to my config
My gradle configuration looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-R'
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "my.application.id"
minSdkVersion 23
targetSdkVersion 29
versionCode 2
versionName "1.1"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'https://maven.google.com' }
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'androidx.navigation:navigation-fragment:2.3.1'
implementation 'androidx.navigation:navigation-ui:2.3.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation 'androidx.multidex:multidex:2.0.1'
}
Guys, I am out of ideas as I am no expert when it comes to gradle. Help would be most appreciated.
I found a temporary solution in downgrading my Android Studio version to 4.0.2.
Additionally, I changed the Android gradle plugin version to 4.0.2 and the gradle version to 6.1.1 which I had installed before. You can do this under File -> Project Structure -> Project.
Now I am able to run my application again. I am aware that this is only a temporary solution but at least I can work again on my application.
I will try to install Android Studio 4.2 Canary 15 the next days and check, if this works for me. I let you know.
This is what usually works for me every time i make an update, I hope it works for you.
Sometimes gradle build fails because, downloading some dependencies required by gradle for a successful build are missing and need to be downloaded. So make sure your computer is online.
-> Click on gradle (right side of your android studio), then toggle the highlighted button in the pic below.
Make sure its not highlighted, Cause if it is highlighted that means gradle is offline (has no access to internet)
Then rebuild project to download the missing gradle dependencies.
I hope you find this useful.
this solution may help. I had problems with this error showing up and I had no idea why. As it turns out, I save my android projects to a USB stick. The USB stick is formatted using PAL. I reformatted using NTFS and the problem has gone.
I had a similar problem this morning after updating my Android studio. In my case, previous projects run well but if I create a new project and attempt to run, I will get the said error message. I changed the Android Gradle plugin version to 4.0.2 and the Gradle version to 6.1.1 from the project structure dialog and I was able to run the app successfully afterward.
I have this problem when I try to build apk with capacitor Ionic in Android Studio. My solution was:
First change the Android Gradle plugin in build.gradle to classpath 'com.android.tools.build:gradle:4.0.2' and in gradle-wrapper.properties change Gradle version to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip and press Sync Now.
When gradle sync is finish, close Android Studio Editor and go to project folder and inside android delete .idea and .gradle folders. Next you need to open PowerSheel in this location and run the code .\gradlew clean.
Finally, you can open the project with android studio using in vs npx cap open android or as you want, wait for sync gradle and then you can build your apk.
Changing the location my projects from a FAT32 formatted drive to an NTFS drive solved the problem for me.

The sdk platform-tools version (26.0.2) is too old to check APIs compiled with API 27; please update

I'm using IntelliJ Idea Community Edition 2017.2.5 and am building an Android app.
My problem is that even if in my app (Gradle) I have:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
defaultConfig {
applicationId "com.app.mtvtr"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:design:27.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'com.android.support:support-v4:27.0.0'
testCompile 'junit:junit:4.12'
}
Also, on first build of the project, compile for the appcompat, design and support was set to 27+ (which IMHO is bad practice and is already pointed by the Studio as a bad idea), so using which tools that I have, I have set it to 27.0.1, and later to 27.0.0 just for the testing if it might work..
In my Fragments and Activities I have:
And the warning says:
The sdk platform-tools version (26.0.2) is too old to check APIs
compiled with API 27; please update
Now, I know that there are topics on SO regarding old and new versions, but I have (to my belief) set the Gradle properly and I am nowhere using platform-tools version 26 or even 26.0.2...
I have tried Restarting and invalidating caches three times.
The project properly builds onto the device and everything works. But, of course, I want to fix the warning. (And not hide it like some would suggest..)
Two things that come to mind are:
I missed somewhere that I should have updated the version, maybe?
I need to start a new project from scratch.
Any ideas? :)
Android Studio 3.0 will be merged into IntelliJ IDEA 2017.3 version, which will make the com.android.tools.build:gradle:3.0.0 plugin compatible with it. That will make this error to go away.
For those of you who are experiencing this issue in Android Studio, check your root build.gradle file and make sure it is updated to the above mentioned plugin version (3.0.0), in order to be able to compile against API 27 with the current latest build tools (26.0.2).
You may consequently also have to update the Gradle wrapper to the latest (4.1 at the time of this answer).
You have just to launch the SDK Manager and download the Android SDK Platform Tools and SDK Tools.
Here the official doc.
It seems that it was an IDE problem because it worked without warnings inside Android Studio 3.0 as it was suggested by CrazyCoder.
It seems that at this moment IntelliJ Idea isn't updated enough to make this work properly. So even while I have been using Idea from the start, I will switch to AS for now. :)
Thanks for your input guys. :)

Why Warning:Unable to find optional library: org.apache.http.legacy occurs?

My gradle file:
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.skripsi.irwanto.paud"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProauardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.11
}
And I get Warning:Unable to find optional library: org.apache.http.legacy
I guess, the easier way to solve this issue without having to reinstall the SDK is to create a file called 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
}
]
It solved the problem for me.
EDIT: Information taken from #domoch's answer below on how to locate your SDK location
To Locate your Android SDK's Location
Go to Android Studio Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location. In Windows, it usually would be pointing to C:\Users\<username>\AppData\Local\Android\sdk.
I had exactly the same issue. Please check if you have android-sdk-windows\platforms\android-23\optional\optional.json file in place. If not then just reinstall API 23 (remove and install again).
Why? If you use Android Studio on Windows then optional.json file should be not only in \Program Files (x86)\...\platforms\android-23\optional\ .
So: go to Android Studio Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location, copy (or create) optional.json in corresponding folder.
Or just edit Android SDK Location to \Program Files (x86)\...
In my case Android SDK Location was C:\Users\Usernade\AppData\Local\Android\sdk and there was no optional.json file.
Settings -> Appearence & Behavior -> System Settings and look for Android SDK Location
platforms/Android 23/optional/
org.apache.http.legacy jar file is copy and paste your android studio project lib and this jar file gradle compile files('libs/org.apache.http.legacy.jar')
The error is that the optional.json file is not in the <sdk-path>\platforms\android-23\optional\ folder.
I solved this by the following:
Go to the sdk manager
Select Android Sdk and updates are available in the Appropriate API level.
Just update it.

Android Studio project build issue

I'm having some strange issue with Android Studio recently. I'm trying to build a project after few modification in code. But the APK got installed is of old code. (I found this by debugging. When I debugged it was going to empty lines) But all my latest code are saved and it's there. I have tried the following steps which I know.
Delete the build folders of Project and Module manually > Restart Studio > Clean Project > Rebuild Project
Restart Android Studio and (I don't know why I restarted but I did that too)
Invalidate and Cache Restart
At some point I found a issue in XML related to style attribute for button which was like style:attr/buttonBarButtonStyle I later corrected to style:"?android:attr/buttonBarButtonStyle"I hope this change is correct because it don't show any more error.
And finally it doesn't give me any error in stacktrace. Project always shows BUILD SUCCESSFUL
Nothing above helped me.
EDIT 1 : I have updated my Android Support Library to 22.1.1 latest version which released a couple of days ago
EDIT 2 : I uninstalled Android Studio. Deleted Android Studio related folders in C:\Program Files\Android\Android Studio and also deleted C:\Users\MyUserName\.android & .AndroidStudio & .gradle folders. And did fresh install of Android Studio. Later I imported a same project and build it. Again it happens in same way! I have also tried running the same project in other lap and it runs without any problem. I Don't know what else I'm missing here
EDIT 3 : Updating my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
signingConfigs {
debug {
storeFile file("./debugkeystore/MyAppDebug.keystore")
}
}
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.1.+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
I just again uninstalled AndroidStudio and clear the registery and made it like a fresh install for the 3rd time and I don't know how but this time it worked! But didn't get what exactly happened!
I solved it by rebuilding the project. Go to the build tab
you should configure Run/Debug Configuration again and add to "Before launch" section "Gradle-aware Make"
that's it

Android Studio: Failed to find: 'com.android.support:support-v4:19.1.0'

I want to build an app in Android Studio with the support library but I get the following error when adding the dependency for the support library:
Error:Failed to find: com.android.support:support-v4:19.1.0
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
applicationId "sample.myapplication"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
}
I have downloaded the support library via the sdk manager.
Ok, found the problem. The Android support repository was missing. After installing and restarting Android Studio it worked.
If you are using Android Studio, then as an addition to changing the build.gradle file manually, you can also lookup the dependency via the library dependencies under the Project Structure menu item.
Double clicking that dependency will generate this line in build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
}
And also, if you are wondering what this library is about, it's described at the developer pages at developer.android.com; Support Library.
My Android Studio version is 1.1. I select tools->Android->SDK Manager, check the Android Support Library then click Install packages, solved this issue.
In my case the solution was as simple as running Build:Make Project. No amount of gradle syncing or clearing caches would do it. Of course, that required getting my project into a state where it would build successfully.
In my case I needed to add Google Maven repository.
It shows as part of the error in Android Studio and only needed to click on it to add itself.
Then Gradle built the project on its own.
Following the instruction here helped me. For whatever reason when I had to reinstall the latest version of android studio the initial download of the extras section android support library failed. I simply retried it. Followed the steps mentioned and verified it was added to the build.gradle file and did a rebuild project and good to go.
http://developer.android.com/tools/support-library/setup.html

Categories

Resources