How to change the compile version in Android Studio? - android

I always use eclipse to build an android project. When I use the eclipse to start a new project, I can choose the compile version. But in Android Studio, I can only choose the min version when I start a new module. I tried to change the compileSdkVersion in build.gradle. But when I clean the project ,I got a lot of errors.Most of them are something like No resource found that matches the given name ....
Here is my build.gradle
compileSdkVersion 16
buildToolsVersion "23.0.1"`
So my question is :How can I assign the compile version when I start the new module at the first time just like what I always do in the eclipse ?

Open your project;
Choose menu item File->Project Structure, and click your modules (like MyApp), and you will find "Compile Sdk Version" in Properties tab.

Related

Cannot resolve symbol 'Theme' in styles.xml (Android Studio)

Since today, Android Studio can't find the AppCompat themes in styles.xml, but for example AppCompatActivity in code does get recognized. My Android Studio version is 2.2.2, Build #AI-145.3360264
I already tried upgrading to the latest build tools, compile sdk (25) version etc. but it didn't fix the problem.
At the moment I have installed the following (from sdk manager):
android api: 19 and 23
sdk platform tools: 25.0.1
sdk tools: 25.2.3
build-tools: 23.0.2 and 25.0.1
support repository: 40
google repository: 39
and a few others, that shouldn't be necessary to list here.
build.gradle of app:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '25.0.1'
defaultConfig {
applicationId "xxx.xxxxxxxx.xxxxxxxxx" //not the real applicationId
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/RootTools.jar')
compile 'com.android.support:support-v4:23.+'
compile 'com.android.support:support-v13:23.+'
compile 'com.android.support:appcompat-v7:23.+'
compile 'com.android.support:design:23.+'
compile 'com.android.support:cardview-v7:23.+'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
compile 'de.hdodenhof:circleimageview:2.1.0'
}
Another solution that worked for me with Android Studio 3.1.2:
delete these from build.gradle if you have them:
'com.android.support:appcompat-v7:27.1.1'
'com.android.support:design:27.1.1'
then sync,
then undo delete,
then sync again.
I encountered this after updating to Android Studio 3.1.
None of the other answers listed here worked for me, however when I switched my appcompat support lib version to the latest 28.0.0-alpha1 then back to 27.1.0 that it was on before, it worked.
Seems the new version of Android Studio lost connection to where the library was synced to and just needed to have it reset.
No need to change anything.
Just press small button on top "Sync Project with Gradle Files"
EDIT: As #Alexey noted, bug still appears in Android Studio v3.1.4
This worked for me:
Click File > Close Project
Reopen the project from Studio's dialog.
That's because of feature called "build cache" that is enabled by default in build Android Plugin since 2.3.0.
It creates files in build cache outside of project folder (in my case -- in \Users\%username%\.android\build-cache)
Theese files are intended to be common between your projects.
And then Android Studio is unable to navigate in theese files.
That's all.
If you want to disable Build Cache, add android.enableBuildCache=false to gradle.properties file. Then restart Android Studio.
more info here:
https://developer.android.com/studio/build/build-cache.html#disable_build_cache
I have had the same problem. The only solution that worked for me was to manually delete the support libraries in file system and sync the project to let Android Studio download them again.
Steps:
Go to your project folder in File system
Go to .idea\libraries
Delete all the Gradle__com_android_support_****.xml files
Open Android Studio
Select File > Sync with File System
Once that is done, Select File > Sync Project with Gradle Files
Build Project
And now your error should be gone!!!
you can hit file -> invalidate Caches / Restart ... if it doesn't fix the issue you can close the project (file-> close project) and import it (file -> new -> import project.
I switched support lib to version 27.1.1 and problem has been solved. Seems like some bug in 27.1.0
I went through the same problem when I upgraded to alpha-2.
I looked at this link: http://tools.android.com/recent, but the only thing that worked well was:
Change this:
Classpath 'com.android.tools.build:gradle:2.3.0-alpha2'
For this:
Classpath 'com.android.tools.build:gradle:2.2.3'
In your build.gradle (Project)
Only this worked for me
Close project (File> Close Project)
Import / Re-Open project again (NOT from Recent)
Error should be resolved now.
If that fails, try below-
Open build.gradle, remove appcompact-v7 dependency and sync project.
Add appcompact-v7 dependency and sync.
I encountered same problem like this.Just the difference is I was using Studio 2.2.3. This is what solved my problem:
In my project level gradle I had:
classpath 'com.android.tools.build:gradle:2.3.0-alpha2' (which was a result of updating studio)
which I replaced with:
classpath 'com.android.tools.build:gradle:2.2.3'
I think you should look for a compatible classpath for your gradle configuration.
I was having the same issue after linking Firebase to my app. Updating the build.gradle in the app module did the trick, updated to:
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.8.0'
I had also the same problem when I upgraded my android studio from 2.2.2 to 2.3 Canary Version.
Although the new beta version of 2.3 is released yet it is using the gradle plugin of 2.2.3 which is of stable version.
So just change the classpath dependency in buildscript of build.gradle project level from alpha to 2.2.3 and sync it. It'll resolve the issue or change to the more appropriate version with respect to your channel version.
More on gradle watch this Gradle Recipes for android Ken Kousen - Gradle Summit 2016
https://www.youtube.com/watch?v=4L6wHTVmxGA
In newer versions of Android Studio, we are asked to use 'AppCompat'. Some users uncheck that and still use the Theme.AppCompat. That makes up this error. Same happened with me.
Solution is to add this line in your build.gradle (app).
compile 'com.android.support:appcompat-v7:26.1.0'
#Daniel Wilson made a comment in one of the answers that solved this issue for me. I wanted to add add as an answer to draw more attention to this solution.
Updating compileSdkVersion and targetSdkVersion from 26 to 27 (and then of course updating the dependencies) eliminated the errors for me.
Mine was fixed by deleting the .gradle file from the folder and re-importing the project in Android Studio
I also faced the problem with Android Studio 3.1 , syncing does not help me.
Then I switched back to
`'com.android.support:design:27.1.0'` from : `'com.android.support:design:27.1.1'`
and added android.enableBuildCache=false to gradle.properties to disable build cache
This is weird, I encounter this problem as below:
Android Studio is 3.1.2
support lib version is 27.0.0
I solve this by below:
change support lib version to 27.1.0, and "Sync Project with Gradle Files", then this error disappear
change support lib version to 27.0.0,and "Sync Project with Gradle Files", then this error not appear again
Deleted .idea and .gradle from project folder.
Then sync with gradle files, it worked.
I ran into the same problem when updating the Android Studio software.
What I did was this:
Go to the Gradle Settings as follows (this path is for Mac, but should be similar on Windows):
Android Studio -> Preferences -> Build, Execution, Deployment ->
Gradle.
Then pick "Use default gradle wrapper (recommended)".
If you already have that option chosen then your problem must lie somewhere else.
I changed my gradle version from
classpath 'com.android.tools.build:gradle:2.3.0'
to
classpath 'com.android.tools.build:gradle:2.2.3'
and it works now!
In Android Studio 3.1.3, the simple work around:
"Sync Project with Gradle Files"
If none of these methods mentioned by other contributors does not work for you..
Then please simply ignore this...
Even flutter officials also said to ignore these errors..
Caution*** Only ignore after trying all the methods.If above methods solve your errors then fine otherwise you can ignore these..
This type of errors happen after installing latest version of flutter sdk,gradle ,android studio and other plugins -packages
If you are using latest version then you have to ignore these errors.

Compile errors when importing ArduDroid to Android Studio

Im importing this old ArduDroid project (https://github.com/xgxzatx/ArduDroid) into Android Studio 1.5.1. At first I got an unrecoverable error due to the ActionBarSherlock library and Android Studio wouldn't even import the project. I followed a post that suggested commenting out the call in project.properties for that library and then importing, so I did and the project imported successfully into Android Studio. Then I downloaded the ActionBarSherlock folder and put that into my project folder so it is recognized, which it is.
Now I've gotten quite a few errors asking for a different SDK and build tools. So far I've tried SDK 19 and the default 22 which I guess installed with Android Studio. The problem seems to be that the ActionBarSherlock seems to be set for SDK 19 but the project seems to be set at a different SDK. I also believe it has something to do with ActionBarSherlock only compiling as far up as SDK 19.
Currently these are my settings:
Ive installed SDK's:
22
19
15
AndroidProject
AndroidManifest.xml>>>min:15, target:15
build.gradle>>>>>>>>>>compile:15, buildTools:22.0.1, min:15, target:15
ActionBarSherlock
AndroidManifest.xml>>>min:15, target:15
build.gradle>>>>>>>>>>compile:19, buildTools:19.1.0
project.properties>>>>target=android-15
Now I'm getting:
Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock'
Ok, I removed the entire project folder from my workspace and started over again:
Commented out this line in the project.properties using TextEdit:
android.library.reference.1=../../JakeWharton-ActionBarSherlock-e5c2d1c/library
Imported the project into Android Studio.
Noticed I have a Project build.gradle, Module build.gradle.
Did not paste the ActionBarSherlock folder into the project in Android Studio this time.
Added these lines to the Module build.gradle:
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.0'
}
Left Module build.gradle as:
compileSdkVersion 15
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.xgxzatx.ardudroid"
minSdkVersion 8
targetSdkVersion 15
}
Left AndroidManifest.xml with min=8 and target=15
However when I run the app on my phone I just get a blank screen with a Configuration tab and a Monitoring tab, but ArduDroid is supposed to have lots of buttons and sliders and a few text fields at the bottom, like this:
but what I get is like this:
So Im guessing this might have been a work in progress that the author never finished? Can anyone else run the project and confirm?

New to intellij android studio, can't open sample projects without Gradle error

i just switched to intellij and pretty new to android development.. I've been working on one app for 5 moth and now that i moved it to intellij android studio my options menus became invisible. I've been reading a lot and trying to catch up with newest features that are available now today.
By biggest pain is that im hitting this error ->
Failed to refresh Gradle project 'ActionBarCompat-ListPopupMenu' You are using Gradle version 1.8, which is not supported. Please use version 1.9. Please point to a supported Gradle version in the project's Gradle settings or in the project's Gradle wrapper (
I did search on this problem and some pages suggesting changing classpath to soething like
build:gradle:0.7.+ but that doest help..
What am i doing wrong? All i need is just to make those examples from android to work..
Thanks
The Gradle wrapper file is at the path (project-root)/gradle/wrapper/gradle-wrapper.properties. The distributionUrl property is where you set the Gradle version; it's embedded in the URL:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip
First make sure you've updated to the newest Android SDK Build-tools version, the most current one is 19.0.3; if you haven't, then open the Android SDK manager and update.
Then look in the build.gradle file inside your project folder (not the one in the root folder). This first couple of lines should resemble something like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
Set the class path to com.android.tools.build:gradle:0.9.+.
Then further along in the same file:
android {
compileSdkVersion 18
buildToolsVersion "19.0.3"
...
}
Set buildToolsVersion to 19.0.3 (the newest version).
Make sure Android Studio syncs the Gradle file changes. If it doesn't, restart Android Studio and/or rebuild the project. Then you should be good to go.
I think i figured this out.. Big thanks to Scott and Jaap.
I did updateof my intellij to 0.5.2, also i installed 19.0.3 ( newest build tools).
On few of the existing projects i had to change distributionUrl to
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
After rebuilding the project it worked like a charm.
Just a note to say : Scorr Berba's reply was probably the correct one. Also I'm not sure 1.11 can be used - I used the wrapper (there is a lot of confusion here : the wrapper is the gradlew ["gradle*w*"rapper] to set the gradle used for my samples to 1.10 and you must set up your project to use the wrapper OR you can build from the command line e.g "./gradlew build".

Android Studio IDE unable to refer to classes from a library module

I'm using Android Studio 0.2.2
I've imported an existing eclipse project, which has the classic eclipse ADT project
structure and added a gradle build script into it.
Let's name it ProjectA
Then I created a module in it, which has the new Android Studio structure,
And added it as library in File>Project Structure dialog.
Let's name it LibA
The problem is this - ProjectA is somewhy lacking the classpath of LibA and therefore the IDE's java parser fails to see classes from LibA, therefore I'm getting a lot of errors on
the IDE's side.
Gradle of course, compiles everything ok because the build process is no longer related to the IDE as it were in Eclipse.
Anyone got any pointers in the matter?
Thanks!
If you are trying to add a library, go to
File -> Project Structure -> Libraries -> click + then add the jar.
Once it has been added, it will ask you for the module which is dependent on jar. Select ProjectA from the list. That should link the library to Module.
After setup dependencies in build.gradle:
try "Tools -> Android -> Sync Project with Gradle Files"
Set up you configs like this:
/settings.gradle
include ':LibA', ':progect'
/project/build.gradle
apply plugin: 'android'
dependencies {
compile project(':LibA')
}
android {
compileSdkVersion 18
buildToolsVersion "18"
defaultConfig {
minSdkVersion 7
targetSdkVersion 18
}
}

Android Studio with Google Play Services

I'm trying to test Google Play Services with the new Android Studio.
I have a project with a dependency to the google_play_services.jar.
But when I try to Rebuild the project I get the following errors:
Information:[TstGP3-TstGP3] Crunching PNG Files in source dir: C:\Users\ans\AndroidStudioProjects\TstGP3\TstGP3\src\main\res
Information:[TstGP3-TstGP3] To destination dir: C:\Users\ans\AndroidStudioProjects\TstGP3\build\classes\res-cache\TstGP3-TstGP3
Information:Compilation completed with 2 errors and 0 warnings in 2 sec
Information:2 errors
Information:0 warnings
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\Android_BuildConfig_Generator\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\BuildConfig.java
Error:Error:line (4)error: duplicate class: com.example.tstgp3.BuildConfig
C:\Users\ans\.AndroidStudioPreview\system\compiler\tstgp3.3f17bd41\.generated\aapt\TstGP3-TstGP3.74fc5b25\production\com\example\tstgp3\R.java
Error:Error:line (10)error: duplicate class: com.example.tstgp3.R
It seems that it has two BuildConfig files and also two R classes. How can I resolve the issue?
EDIT:
I have noticed that the compiler compiles two R.java files: the one that is in my project folder and another one that is located in the folder %USERPROFILE%.AndroidStudioPreview
So, I tried to exclude this "Preview" folder in the compiler settings and now it's working.
This issue only occurs after I have started to use Google Play Services classes in my project.
I will appreciate if someone can explain the reason behind this problem.
All those answers are wrong, since the release of gradle plugin v0.4.2 the setup of google play services under android studio is straight forward. You don't need to import any jar or add any project library nor add any new module under android studio. What you have to do is to add the correct dependencies into the build.gradle file. Please take a look to those links: Gradle plugin v0.4.2 update, New Build System, and this sample
The Correct way to do so is as follows:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
Restart android studio and open the build gradle file. You must modify your build.gradle file to look like this under dependencies:
dependencies {
compile 'com.google.android.gms:play-services:6.5.87'
}
And finally syncronise your project (the button to the left of the AVD manager).
Since version 6.5 you can include the complete library (very large) or just the modules that you need (Best Option). I.e if you only need Google Maps and Analytics you can replace the previous example with the following one:
dependencies {
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.google.android.gms:play-services-maps:6.5.87'
}
You can find the complete dependency list here
Some side notes:
Use the latest play services library version. If it's an old version, android studio will highlight it. As of today (February 5th is 6.5.87) but you can check the latest version at Gradle Please
After a major update of Android Studio, clean an rebuild your project by following the next instructions as suggested in the comments by #user123321
cd to your project folder
./gradlew clean
./gradlew build
Go to File -> Project Structure
Select 'Project Settings'
Select 'Dependencies' Tab
Click '+' and select '1.Library Dependencies'
Search for : com.google.android.gms:play-services
Select the latest version and click 'OK'
Voila! No need to fight with Gradle :)
EDITED: This guy really brought it home and has a good little tutorial
http://instantiatorgratification.blogspot.com/2013/05/google-play-services-with-android-studio.html
one side note: I had played around so much that I needed to do a gradlew clean to get it to run succesfully
If you have imported your project or are working from the Sample Maps application located in \extras\google\google_play_services\samples\maps check out this tutorial.
https://stackoverflow.com/a/16598478/2414698
If you are creating a new project from scratch then note Xav's comments on that same post. He describes that Android Studio uses a different compiler and that you have to modify the build.gradle file manually. I did this with success. I copied
google-play-services.jar
google-play-services.jar.properties
into my lib directory and added the following to my build.gradle file
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/google-play-services.jar')
}
Also, if this is a new project check out this post, too.
https://stackoverflow.com/a/16671865/2414698
Most of these answers only address compile-time dependencies, but you'll find a host of NoClassDef exceptions at runtime. That's because you need more than the google-play-services.jar. It references resources that are part of the library project, and those are not included correctly if you only have the jar.
What worked best for me was to first get the project setup correctly in eclipse. Have your project structured so that it includes both your app and the library, as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Multi-project-setup
Then export your app project from eclipse, and import into Android Studio as described here: http://developer.android.com/sdk/installing/migrate.html. Make sure to export both your app project and the google play services library project. When importing it will detect the library project and import it as a module. I just accepted all defaults during the project import process.
Google Play services Integration in Android studio.
Step 1:
SDK manager->Tools Update this
1.Google play services
2.Android Support Repository
Step 2:
chance in build.gradle
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:4.0.+'
}
Step 3:
android.manifest.xml
<uses-sdk
android:minSdkVersion="8" />
Step 4:
Sync project file with grandle.
wait for few minute.
Step 5:
File->Project Structure find error with red bulb images,click on go to add dependencies select your app module.
Save
Please put comment if you have require help.
Happy coding.
None of the above solution worked for me. Not sure if it is specific to my setup or new release.
I am using Android Studio Beta 0.8.9 and I was not getting any com.google.android.gms:play-service in the library list on following this instruction:
Go to File -> Project Structure -> Select Project Settings -> Select 'Dependencies' Tab Click '+' -> 1.Library Dependencies -> Select com.google.android.gms:play-services:+
I had already done this:
First of all you have to launch the sdk manager and download and install the following files located under "extras": Android support repository, Google play services, Google repository.
What resolved it was to add from SDK Manager, "Google play services for Froyo" then repeating the first step.
Did not understand the reason properly but this worked.
PS: I just observed that even now when I search for play-services this does not come, but when I directly scroll and look through the list it is right there.
Follow this article -> http://developer.android.com/google/play-services/setup.html
You should to choose Using Android Studio
Example Gradle file:
Note: Open the build.gradle file inside your application module
directory.
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "{applicationId}"
minSdkVersion 14
targetSdkVersion 20
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:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.1.+'
}
You can find latest version of Google Play Services here: https://developer.android.com/google/play-services/index.html
I've got this working after doing the following:
Have the google-play-services-lib as a module (note difference between module and project), then add the google-play-services.jar to your models "libs" directory.
After that add the jar to your build path through making a library or add the jar to another library. I generally have a single IDEA library which I add all my /libs/*.jar files to.
Add the library to your modules build path through Module Settings (F4).
Add the google-play-services-lib as a module dependency to your project.
Done!
Note: This doesn't give me the runtime exceptions either, it works.
Open your project build.gradle file and add below line under dependencies module.
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
}
The below will be add Google Analytics and Maps if you don't want to integrate full library
dependencies {
compile 'com.google.android.gms:play-services-analytics:7.0.0'
compile 'com.google.android.gms:play-services-maps:7.0.0'
}
In my case google-play-services_lib are integrate as module (External Libs) for Google map & GCM in my project.
Now, these time require to implement Google Places Autocomplete API but problem is that's code are new and my libs are old so some class not found:
following these steps...
1> Update Google play service into SDK Manager
2> select new .jar file of google play service (Sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs) replace with old one
i got success...!!!
I copied the play libs files from the google-play-services_lib to my project libs directory:
google-play-services.jar
google-play-services.jar.properties.
Then selected them, right-click, "Add as libraries".

Categories

Resources