I am using android studio and when i try to create a new project i found that the manifest file always contains android:name=".MainActivity" highlighted
with red as well as AppCompatActivity, onCreate and setContentView in the following code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Please let me know how solve it
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.com.myapplication"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
style:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">//cant
resolve symbol Theme+cant resolve symbol AppCompat
</style>
Try sync project with build.gradle.
Do you set right sdk path.
This usually happens when you need to upgrade Android Studio. Please go to
-Tools/Android/SDK Manager, 'Launch Standalone SDK Manager' (at the bottom) and install what it has pre-selected.
Sometimes when you have errors it will pop up in the top right of Android Studio presenting you with a 'Fix' button as well, try re-starting Android Studio and looking out for this option.
If the above suggestions don't work let me know and I'll look further into it.
EDIT: You have not included the support library dependency. This is why Android Studio cannot find AppCompat etc. Please go to your app level build.gradle file and include this line under 'dependencies' and re-sync your project (as it will ask you to do).
compile 'com.android.support:appcompat-v7:23.1.1'
Check if you are using the right versions for these lines. You are possibly using an older version of Build Tools or AppCompat library in your IDE. Maybe Android Studio is not updating the versions in your manifest file when you create a new project.
buildToolsVersion "23.0.2"<--- This line
compile 'com.android.support:appcompat-v7:23.0.1'<--- This line
After installing the updated version of both of these lines, sync project.
Related
Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here
I am using Android Studio 1.2.2 to develop an Android Application. In my build.gradle file, I have defined the compileSdkVersion to 21 since the beginning of the work. Now I wanted to change that to 19, since this software actually will never be installed on an Android device, that runs a higher version than Android 4.4
When I try to change this value to 19, the project does not compile anymore.
After the change of the version value I have:
synced the project
cleaned the project
rebuild the project (tried)
But the following error occurs:
In the file /projectpath/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/res/values-v21/values-v21.xml it marks 103 errors, saying "cannot resolve symbol".
values-v21.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- From: file:/usr/local/google/buildbot/repo_clients/https___googleplex-android.googlesource.com_a_platform_manifest.git/lmp-mr1-supportlib-release/frameworks/support/v7/appcompat/res/values-v21/styles_base_text.xml -->
<eat-comment/>
<style name="Base.TextAppearance.AppCompat" parent="android:TextAppearance.Material"/>
<style name="Base.TextAppearance.AppCompat.Body1" parent="android:TextAppearance.Material.Body1"/>
<style name="Base.TextAppearance.AppCompat.Body2" parent="android:TextAppearance.Material.Body2"/>
<style name="Base.TextAppearance.AppCompat.Button" parent="android:TextAppearance.Material.Button"/>
....
cannot resovle symbol android:TextAppearance.Material
cannot resovle symbol android:TextAppearance.Material.Body1
cannot resovle symbol android:TextAppearance.Material.Body2
cannot resovle symbol android:TextAppearance.Material.Button
and so on...
What is causing this error? What can I do to make it compile again?
When I change back the compileSdkVersion to 21, everything works normal again.
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '23.0.0 rc3'
defaultConfig {
applicationId 'com.appname.id'
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "0.0.2 Alpha"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
to use appcompat-v7:22.2.0 you have to compile against API 21. There's no harm in doing it, even if it will never run on devices running 21.
You can try some older version of the app compat, but then you will be missing in "cool new features" and bug fixes from the latest app compat.
If this might help someone, after MANY trials and errors, I found that I was targeting the wrong SDK version (an older one) in the build.gradle file corresponding to "library". To change this you can do it by hand or go to the Module Settings Menu (right click on your project folder -> Open Module Settings. Then in "library" - Properties you can change the Compile Sdk and the Build Tools Versions
make sure you have installed API 19 in sdk manager
I am trying to do an application but there seems to be some error with the gradle files now. It was working fine until I upgraded the support libraries.
I was working with api 21 which worked fine, but then i upgraded to api22 and changed the gradle files accordingly.. Now this error shows up.
Error:Failed to find: com.android.support:support-v4:22.2.0
This is my current gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.sampleapp"
minSdkVersion 12
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.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.jakewharton:butterknife:6.1.0'
}
Any help would be appreciated.
If this might help someone, after MANY trials and errors, I found that I was targeting the wrong SDK version (an older one) in the build.gradle file corresponding to "library". To change this you can do it by hand or go to the Module Settings Menu (right click on your project folder -> Open Module Settings. Then in "library" - Properties you can change the Compile Sdk and the Build Tools Versions
Using Android SDK Manager. Go to Extras and then Android Support Repository and update it to the latest version.
(This is essentially the comment #natario made, but it should be an answer.)
Situation:
I'm currently building a new version of my app for Android L and am also in the process of Chromecast integration.
The app works fine, as long as I extend Theme.Material with my custom style, but doesn't show the Cast button.
Problem:
As soon as I change to Theme.AppCompat, it gives me the error:
Error:Error retrieving parent for item: No resource found that matches the given name '#android:style/Theme.AppCompat.Light.DarkActionBar'.
and the same goes for the the Holo Theme as well.
Here's my build.gradle (The libs folder is empty btw.):
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.myapp.myapp"
minSdkVersion 'android-L'
targetSdkVersion 'android-L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:mediarouter-v7:+'
compile 'com.google.android.gms:play-services:+'
}
Here is the relevant part of the values/styles.xml:
<style name="SK" parent="android:Theme.AppCompat.Light.DarkActionBar">
used to work with Theme.Holo.Light.DarkActionBar
and the values-v21/styles.xml:
<style name="SK" parent="#android:style/Theme.AppCompat.Light.DarkActionBar">
used to wirk with Theme.Material.Light.DarkActionBar
I already cleaned and rebuild the project, but it always goes back to showing me errors about a missing parent.
As far as I could gather from similar questions, all relevant libraries are included and all use the newest version available.
I also tried manually adding the libraries to the libs/ folder with no success.
My SDK manager shows that everything is installed and up to date.
What am I missing here?
Thanks in advance for your time.
Solution:
It was actually rather simple. I referred to Theme.AppCompat with the android namespace, but should have left it out, so, instead of
#android:style/Theme.AppCompat
it should be
#style/Theme.AppCompat
This did show another error initially, about "Theme" not being found, but it compiled non the less.
I've imported a library in Android studio (0.5.3)
My settings.graddle looks like this:
include ':app', ':libs:Android-PullToRefresh-master'
And my build.graddle looks like this:
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:19.+'
compile 'com.android.support:support-v4:19.+'
compile 'com.google.android.gms:play-services:4.2.42'
compile fileTree(dir: 'libs', include: ['*.jar'])
project(':libs:Android-PullToRefresh-master');
}
The folder I've downloaded is placed in the libs folder directly under the app folder. Also the graddle syncs and building doesn't provide any error. Yet whenever I try to import import com.handmark.xxxxxx; I get the error cannot resolve symbol 'handmark'. I've chcecked to project structure and the app has the dependency in the list.
What is going wrong and how can I fix this?
I ran into the same issue here and asked the question on the "Android Developer Tools" Google+'s community. Alex Ruiz picked up the conversation and told me:
I'm able to reproduce this issue. Unfortunately, no updates yet. We
are currently fixing the "Project Structure" (the core
infrastructure,) and we will get to this, hopefully soon.
So they are aware of it but we still have to wait until they fix it.
In the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new lib.
I had the exact same problem as this, however the library file was an aar file, and it happened a long time after adding the library and developing with it for a while.
Building on the information Thomas provided; I found to fix this you should replace the file dependency with a maven dependency if possible. A good resource for finding and creating your Gradle dependency is Gradle, please.
That site returns the below dependency when searching for PullToRefresh
dependencies {
compile 'com.loopeer.android.thirdparty.pulltorefresh:Android-PullToRefresh:2.1.1'
}