Android Studio Support Library v7 - android

I am attempting to use the Support Action Bar. I have followed all the instructions on how to include the support library in Android Studio v 0.3.0. My build.gradle's dependencies look like:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':NineOld')
compile project(':Helpshift')
compile project(':SlidingMenu:library')
compile project(':AmbilWarna')
compile 'com.android.support:support-v4:18.0.+'
compile 'com.android.support:appcompat-v7:18.0.+'
}
When I attempt to use the theme:
android:theme="#android:style/Theme.AppCompat"
Android Studio says it cannot resolve the symbol. I know this used to be an issue, but I believe it was fixed in 0.2.6.
When building the project, I get
Gradle: No resource found that matches the given name (at 'theme' with value '#android:style/Theme.AppCompat').
After I clean the project with the dependencies, I should see the jars in the External Libraries. Correct? At the moment, I only see the support-v4-18.0.0 jar.

Remove the "android:" prefix.
Styles and Themes not included in your minimum API level will not be there.
So if you're minimum API level is 8 (Froyo), then any time you prefix a resource with "android:" it's going to look in the android "res" folder for platform-8 (android-sdk\platforms\android-8\data\res).
Lastly, the main reason why you need to use the AppCompat library is because the "Theme.Holo" does not exist in your platform "res" folder unless you raise your minimum API level to 11 (Honeycomb).

Related

Code Duplication Error - Two libraries contain the same classes - Gradle , Android Studio

I am working on a project in Android Studio where there are included two versions of the library lib signal, the default version was: 0.1.4. I have added another version that is 2.8.1. The reason why I have added another version of the library is that the default version, which is also the newest version, doesn't include anymore some of the classes that the older version (2.8.1) does.
On my build.gradle file, here is the way I have included the 2.8.1 version :
dependencies {
lintChecks project(':lintchecks')
implementation ('androidx.appcompat:appcompat:1.2.0') {
force = true
}
implementation fileTree(dir: "libs", include: ["*.jar"])
}
The problem is that I am having a code of duplication error because the older version contains some classes which are exactly the same as the newer version.
My question is: How can I include the older version and exclude the classes that already exist in the other version?

Design support library - Which version to use with SDK v21

I have problems to understand the version scheme of the support libraries and when to use which version. Currently I have a project with compileSdkVersion 21, minSdkVersion 21 and targetSdkVersion 21 and want to use the android design support library.
When I use com.android.support:design:22.2.0 the project compiles but I get a Gradle warning:
"This support library should not use a different version (22) than the `compileSdkVersion` (21)".
When I use com.android.support:design:23.0.1 I get some compilation errors like:
"Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
I thought I can use always the highest version of the support libraries as long as the compileSdkVersion is lower or equal, but that seems wrong.
Can I use the design support library when compiling against API level 21?
Support Library should always match the compileSdkVersion even if the targetSdkVersion or minSdkVersion are lower. If you want to use the design library you will need to set compileSdkVersion to at least 22 and library version 22.2.0.
The reason for that is simple. The version of the library reflects the version of the Android sdk against it was built. If you try to use a higher level version of the support library than the compileSdkVersion it may not find resources that were added in a later version.
You can use one of these:
//You have to use compileSdkVersion=22
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:design:22.2.1'
//You have to use compileSdkVersion=23
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.0.0'
The design library has dependency with appcompat-v7 library.
You can't use the v23.0.x version compiling with api 22 (it is the reason of "Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Also, because the first version of the design library is 22, you can't use compileSdk=21.

How can I add BaseGameUtils to Chrome Cast project?

I'm trying to add a Leader Board to a Chrome cast project and am getting errors. Android project in Android Studio. In my gradle build - Error: more than one library with package name 'com.google.android.gms'
I understand why you don't want to use two different libraries with the same name, but not sure how to use the same library throughout the project. Here are the two uses of gms:
1) Main activity has dependency on 'CastCompanionLibrary-android-master' which then uses google-play-services_lib. I'm not sure which version of gms this uses, but the version number is referenced in the manifest. Is this just grabbing the version # of play services that they have installed on their phone?
2) BaseGameUtils - has dependency on com.google.android.gms:play-services:+ (I think this is grabbing the most recent version of play-services, but doesn't match the other one.
MainActivity gradle file
dependencies {
compile project(':BaseGameUtils')
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':CastCompanionLibrary-android-master')
}
CastCompanionLibrary-android-master dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':android-support-v7-appcompat')
compile project(':android-support-v7-mediarouter')
compile project(':google-play-services_lib')
}
BaseGameUtils dependencies {
compile 'com.android.support:appcompat-v7:20.0.+'
compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:+'
}
So, the problem (I think) is these two versions of com.google.android.gms, but how do I rectify it so that they all use the same version. I've had almost 2 years of working with Android, but this is my first question on stack overflow. Help is appreciated - Is there a guru out there that has the answer to this?
Seems like you have modified the gradle file for CCL since what you have there does not match with what CCL has in GitHub. The best approach is to only use the piece of play services that you need; for example CCL only needs the play-services-cast (besides the base, which will be pulled in automatically) so if you follow that pattern, things would look smaller (less possibility of running into the 64K dex limit) and less collisions.CCL, in Github, lists its dependency as:
compile 'com.google.android.gms:play-services-cast:6.5+' so you might want to start using versions and also follow the recomendation I just made (same applies for any other code that you have and uses play services; just pull in what you really need)

how do I properly install support-v7 repo in Android Studio

Currently my dependencies look like:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/volley_1_0_8.jar')
compile 'com.android.support:support-v4:21.0.2'
compile 'com.android.support:support-v7:21.0.2'
compile files('libs/volley.jar')
compile files('libs/picasso-2.4.0.jar')
}
Which gives me the following error:
Error:Failed to find: com.android.support:support-v4:21.0.2
Install Repository and sync project
Open File
Open in Project Structure dialog
It looks like I have everything needed inside the SDK:
Clicking on "Install Repository and sync project" prompts me to install the support repo rev 9 (which I already have, according to the SDK manager?)
While installing I always get the error
Failed to rename directory C:\Program Files (x86)\Android\android-studio\sdk\extras\android\m2repository to C:\Program Files (x86)\Android\android-studio\sdk\temp\ExtraPackage.old01.
It seems the directory is in use by Android Studio itself.
The question: how can I install the v7 support?
The current version of the support-v4 is 21.0.0. There is no such library as support-v7 - if you mean appcompat-v7, then that is also 21.0.0 as per gradleplease.appspot.com, which is a handy reference for the latest versions of various libraries.
The reason the SDK Manager has the version at 21.0.2 is because other parts of the support library (specifically, the Multidex support library) was changed since the initial release of version 21.0.0, but that did not change the support-v4 or other parts.

How to add recycle view in layout xml

I am following this link, as mentioned in the link I am trying to add recycle view as follows:
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
I have added android-support-v7-appcompat library project and also tried adding recyclerview-v7-21.0.0-rc1.aar to libs but still I am getting following error.
The following classes could not be found:
- android.support.v7.widget.RecyclerView
Note: I have updated Android SDK Tools, Android SDK Platform Tools, Android SDK Build Tools, Android L (API 20, L Preview)
please help..
You can't add the aar file to libs folder in Eclipse (it isn't a jar file)
The best way to work with the new RecyclerView is, currently, to switch to Android Studio and add this dependency to your build.gradle
compile 'com.android.support:recyclerview-v7:+'
Just a note. It is not a good practice to use the '+' placeholder, but in this case you are trying a preview release, so it will be update soon with stable release.
You can use one of these versions.
Check your sdk for updated version:
//it requires compileSdkVersion 23
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
//it requires compileSdkVersion 22
compile 'com.android.support:recyclerview-v7:22.2.1'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.0'
compile 'com.android.support:recyclerview-v7:22.0.0'
//it requires compileSdkVersion 21
compile 'com.android.support:recyclerview-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.2'
compile 'com.android.support:recyclerview-v7:21.0.0'
Of course you can still use Eclipse but it will requires some manual operations.
You can find all the release of the support libraries library in this folder:
sdk/extras/android/m2repository/com/android/support/
Here you can check all version.
In the folders you will find the aar file of the support libraries.
Inside you can check the classes.jar file,the res folder and the AndroidManifest file.
Create a project in your workspace
Unzip the AAR into some directory.
Copy the AndroidManifest.xml, the res, and assets folders from the AAR into your project.
Create a libs directory in your project and copy into it the classes.jar
Add the dependency.
Use the SDK 23 to compile
Mark the project as a library
The Recyclerview library has the support-v4.jar and the support-annotations-23.x.X.jar as dependencies.
ECLIPSE
If your problem is not solved or for future readers , here is the answer: From android sdk manager download Android Support Library first.
Go to this location and copy .aar file from here
X:\android-sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0
Then rename it as .zip file then unZIP it then find classes.jar file , rename it with some proper name like 'RecyclerView_v7.jar' Then copy the that .jar file in you project library. Add it to build path then restart eclipse so that it can be instantiated (not necessary but i had to do this).
**=================================Update=======================**
After new Library Updates; RecyclerView,CardView etc are available as simple library projects.! :)
File~>Import~>Existing Android Code~>SDKpath~>extras~>android~>support~>
v7~>recyclerView.
Then right click on this project , go to properties under Android check Is Library. It is done ..!
Now open your app in which you want to use recyclerView.
goto properties of your app Project under Android add Library here you will find that Library project add that (remember don't make your app a library project by checking 'Is Library'), now go to your App Project's
Properties~>Java Build Path~>Libraries~>Add Jars~>RecyclerView LibraryProject~>libs
Then add that jar into your project and buildpath .! Pheeew.. :)

Categories

Resources