Trying to use the new RecyclerView from the support library. I downloaded the 20 update for the support library using the SDK manager.
I've added the jar file to the libs folder - and added to build path - no luck using the RecyclerView.
Tried to use also the gradle dependency according to Android Developer's API - not sure if this is the right place to look - this page is related more to AndroidTV :
com.android.support:recyclerview-v7:20.0.+
Cannot gradle sync the project.
Any ideas?
Figured it out.
You'll have to add the following gradle dependency :
compile 'com.android.support:recyclerview-v7:+'
another issue I had compiling was the compileSdkVersion. Apparently you'll have to compile it against android-L
Your build.gradle file should look something like this:
apply plugin: 'android'
android {
compileSdkVersion 'android-L'
buildToolsVersion '19.1.0'
[...]
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:+'
}
I have created using following lines and this works for me.
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
For AndroidX
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
This works for me:
compile 'com.android.support:recyclerview-v7:21.0.0-rc1'
RecyclerView can now be added by compiling design dependency in app gradle:
dependencies {
...
compile 'com.android.support:design:24.0.0'
}
If You have Compiled SDK Version 22.2.0 then add below dependency for recycler view and cardview additional for support of cardView
// for including all the libarary in the directory lib
compile fileTree(include: ['*.jar'], dir: 'libs')
// for support appcompat
compile 'com.android.support:appcompat-v7:22.2.0'
//for including google support design (it makes possible of implementing material design theme from 2.3 and higher)
`compile 'com.android.support:design:22.2.0'
for adding the recycler view use following dependency
compile 'com.android.support:recyclerview-v7:22.2.0'
After that click on Build->rebuild project and you are done.
compile 'com.android.support:recyclerview-v7:24.2.1'
This works for me.
Try it.
The steps before me are just missing one step.
After altering the build.gradle (Module:app) and adding the following dependencies:
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
(Add cardview if necessary)
You must then must go to Build > Clean Project to get rid of any errors
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.0'
}
Just make your dependencies like above in build.gradle file, worked for me.
in my case I fixed it by putting compile 'com.android.support:recyclerview-v7:22.0.0' as a dependency into my gradle build
(with Android studio v. 1.2.1.1 and all sdk's updated.)
It's really annoying when codes are updated so fast and the IDE can't keep track of them, and you have to manually fix for them, wasting time and resources.
But well, at last it works.
include the dependency in the build.gradle, and sync the project with gradle files
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:25.1.0'
//include the revision no, i.e 25.1.1
implementation 'com.android.support:recyclerview-v7:25.1.1'
}
Include the revision(here its 25.1.1) to avoid unpredictable builds, check library revisions
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
Above works for me in build.gradle file
I used a small hack to use the RecyclerView on older devices. I just went into my local m2 repository and picked up the RecyclerView source files and put them into my project.
You can find the sourcecode here:
<Android-SDK>\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1\recyclerview-v7-21.0.0-rc1-sources.jar
Other answers did not work for me. I had to add this line:
compile 'com.android.support:recyclerview-v7:21.0.0'
-Go to the DESIGN part in activity_main.xml
-In the drag drop pallet select appCompactivity
-In appCompactivity Select RecyclerView
-On Selection a dialog shall appear click OK
-Your project app:gradle will automatically get updated
My dependencies;
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
//RecyclerView dependency
compile 'com.android.support:recyclerview-v7:25.1.0'
// Instrumentation dependencies use androidTestCompile
// (as opposed to testCompile for local unit tests run in the JVM)
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:25.1.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
}
I added only compile 'com.android.support:recyclerview-v7:25.1.0'. The important thing is to add RecycleView dependency which is as the same version as appcompat
If you using the updated or 2018 Version for Android Studio...
compile 'com.android.support:recyclerview-v7:+'
will give you an error with following message
"Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018."
Try using this
implementation 'com.android.support:recyclerview-v7:+'
I used this one is working for me. One thing needs to be consider that what appcompat version you are using. I am using appcompat-v7:26.+ so this is working for me.
implementation 'com.android.support:recyclerview-v7:26.+'
A great way to import the RecyclerView into your project is the RecyclerViewLib. This is an open source library which pulled out the RecyclerView to make it safe and easy implement. You can read the author's blog post here.
Add the following line as a gradle dependency in your code:
dependencies {
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+#aar'
}
More info for how to bring in gradle dependencies:
Bosnia you're right about that being annoying. Gradle may seem complicated but it is extremely powerful and flexible. Everything is done in the language groovy and learning the gradle system is learning another language just so you can build your Android app. It hurts now, but in the long run you'll love it.
Check out the build.gradle for the same app. https://github.com/twotoasters/RecyclerViewLib/blob/master/sample/build.gradle Where it does the following is where it brings the lib into the module (aka the sample app)
compile (project (':library')) {
exclude group: 'com.android.support', module: 'support-v4'
}
Pay attention to the location of this file. This is not the top level build.gradle
Because the lib source is in the same project it is able to do this with the simple ':library'. The exclude tells the lib to use the sample app's support v4. That isn't necessary but is a good idea. You don't have or want to have the lib's source in your project, so you have to point to the internet for it. In your module's/app's build.gradle you would put that line from the beginning of this answer in the same location. Or, if following the samples example, you could replace ':library' with ' com.twotoasters.RecyclerViewLib:library:1.0.+#aar ' and use the excludes.
import android.support.v7.widget.RecyclerView;
In Android Studio, importing is not as intuitive as one would hope. Try importing this bit and see how it helps!
If anyone still has this issue - you don't have to change compileSdkVersion, this just defeats the whole purpose of support libraries.
Instead, use these in your gradle.build file:
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:palette-v7:+'`
This works for me
Define internet permission
<uses-permission android:name="android.permission.INTERNET" >
Add dependency
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile ('com.squareup.retrofit2:converter-simplexml:2.1.0'){
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
exclude group: 'xpp3', module: 'xpp3'
}
In Main Activity
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
public class MainActivity extends AppCompatActivity {
private BreakfastMenu breakfastMenu;
List<BreakfastMenu> list;
TextView responseText;
APIInterface apiInterface;
String name;
String price;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
responseText=(TextView)findViewById(R.id.reponseText);
apiInterface = APIClient.getClient().create(APIInterface.class);
/**
GET List Resources
**/
Call<BreakfastMenu> call = apiInterface.getBreakfastMenu();
call.enqueue(new Callback<BreakfastMenu>() {
#Override
public void onResponse(Call<BreakfastMenu> call, Response<BreakfastMenu> response) {
Log.d("TAG", response.code() + "");
String displayResponse = "";
BreakfastMenu resource = response.body();
System.out.println(displayResponse+"display response ");
for (Food food : resource.getFoodList())
{
name=food.getName();
price=food.getPrice();
System.out.println(name+price+"=========================================");
displayResponse += food.getName() + " " + food.getPrice()+"\n"+"\n";
Toast.makeText(MainActivity.this,name+price,Toast.LENGTH_LONG).show();
}
responseText.setText(displayResponse);
}
#Override
public void onFailure(Call<BreakfastMenu> call, Throwable t) {
call.cancel();
}
});
}
}
Make APIClient.java class
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.simplexml.SimpleXmlConverterFactory;
class APIClient {
private static Retrofit retrofit = null;
static Retrofit getClient() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
retrofit = new Retrofit.Builder()
.baseUrl("https://www.w3schools.com/")
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
return retrofit;
}
}
enter code here
Make APIInterface.java
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
interface APIInterface {
#GET("xml/simple.xml")
#Headers({"Accept: application/xml",
"User-Agent: Retrofit-Sample-App"})
Call<BreakfastMenu> getBreakfastMenu();
}
In BreakfastMenu.java
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;
import java.util.List;
#Root(name = "breakfast_menu")
public class BreakfastMenu
{
#ElementList(inline = true)
private List<Food> foodList;
public BreakfastMenu()
{
}
public List<Food> getFoodList()
{
return foodList;
}
public void setFoodList(List<Food> foodList)
{
this.foodList = foodList;
}
}
Make Food.java
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;
#Root(name = "food")
public class Food
{
#Element(name = "name")
private String name;
#Element(name = "price")
private String price;
#Element(name = "description")
private String description;
#Element(name = "calories")
private String calories;
public Food()
{
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPrice()
{
return price;
}
public void setPrice(String price)
{
this.price = price;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public String getCalories()
{
return calories;
}
public void setCalories(String calories)
{
this.calories = calories;
}
}
In activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/reponseText"
android:layout_width="match_parent"
android:layout_height="600dp"
/>
</Linear Layout>
Just an update:
'compile' is obsolete now; it has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018 I believe. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
Also all com.android.support libraries must use the exact same version specification; in addition, support libraries such as appcompat-v7 and recyclerview-v7 should not use a different version than the compileSdkVersion.
Related
I am having trouble trying to use Stetho, I've tried to search and follow the steps provided by others but, it seems none of them highlight my problem. Below is what is in my needed files for Stetho utilization.
My problem is it cannot identify the method "initialize" I've tried other ways of implementing the method through the suggestion of other users but, I still meet the same error
build.gradle (Module: app)
dependencies {
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
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:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
testCompile 'junit:junit:4.12'
}
in my Stetho Application Class
import android.app.Application;
public class Stetho extends Application {
#Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
declared in my Manifest
<application
android:name=".Stetho"
android:allowBackup="true"
I thought the problem is, I don't actually have the library implemented correctly, but I am not sure.
You are probably getting name conflicts because your App class is named Stetho as well. Rename your App class on the .java and .manifest files. Import the Stetho package into your app class.
Your app class should look something like this:
import android.app.Application;
import com.facebook.stetho.Stetho;
public class MyApp extends Application {
#Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
And your manifest like this:
<application
android:name=".MyApp"
android:allowBackup="true" />
Using Android Studio I have an Android Module, and a Java module.
In the Java module, I want to use AutoValue to generate immutable classes.
All seems to work fine (files are generated in the Java module) but I'm unable to access those files in the Android project. Any suggestions?
app\build.gradle
apply plugin: 'com.android.application'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':domain')
}
domain\build.gradle
plugins {
id 'net.ltgt.apt' version '0.6'
}
apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.auto.value:auto-value:1.2'
apt 'com.google.auto.value:auto-value:1.2'
}
domain/MyLocation.java
import com.google.auto.value.AutoValue;
#AutoValue
abstract class MyLocation {
abstract String name();
#AutoValue.Builder
abstract static class Builder {
abstract Builder name(String _name);
abstract MyLocation build();
}
}
When I build the domain module (the java module), I see that the 'AutoValue_MyLocation' file is generated here:
\domain\build\generated\source\apt\main\my\package\domain\AutoValue_MyLocation.java
However, I am not able to use the generated class anywhere in my Android module.
Nevermind, by looking at the generated class I saw that it was not public, hence I could not access it in my Android Module.
To fix it, simple make the #AutoValue class public, like so
#AutoValue
public abstract class MyLocation {
//
}
I am new to AWS. I created AWS sample app which works fine. But when I try to add the code to my new application, I am getting error in Application class on import statement.
import com.amazonaws.mobile.AWSMobileClient;
import com.amazonaws.mobile.push.PushManager;
import com.amazonaws.mobile.user.signin.SignInManager;
public class Application extends MultiDexApplication {
private final static String LOG_TAG = Application.class.getSimpleName();
#Override
public void onCreate() {
// My code //
.
.
.
Android studio gives error on "mobile" part of these import statements.
I don't know if any Jars needs to be added in the project.
Gradle code builds without the error.
Following is my gradle code -
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'app/libs')
compile 'com.android.support:design:23.2.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:support-v4:23.1.0'
compile('com.amazonaws:aws-android-sdk-s3:2.2.11')
compile 'com.amazonaws:aws-android-sdk-core:2.+'
compile('com.amazonaws:aws-android-sdk-cognito:2.2.11')
compile('com.amazonaws:aws-android-sdk-mobileanalytics:2.2.11')
compile('com.amazonaws:aws-android-sdk-sns:2.2.11')
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.google.android.gms:play-services-plus:7.8.0'
compile 'com.android.support:multidex:1.0.0'
Let me know if I should add some more of my code here.
The classes you try to import do not exist in the AWS SDK. Check the sample to find out where they come from.
Please read the instructions in the READ_ME/index.html file of your sample download project. The same instructions exist on the Build page in AWS Mobile Hub. There you will find instructions to copy/paste the helper source code that was included in the download into your own project, including the com.amazonaws.mobilehub java package. This source is included in the project download and must be copied to your own product application.
https://forums.aws.amazon.com/forum.jspa?forumID=88
I am attempting to run the test from Robolectric.org's Writing Your First Test page. The test in question looks like this:
#Test
public void clickingLogin_shouldStartLoginActivity() {
WelcomeActivity activity = Robolectric.setupActivity(WelcomeActivity.class);
activity.findViewById(R.id.login).performClick();
Intent expectedIntent = new Intent(activity, WelcomeActivity.class);
assertThat(shadowOf(activity).getNextStartedActivity()).isEqualTo(expectedIntent);
}
I get this compile error: Cannot resolve method 'assertThat(android.content.Intent).
The two possibilities I see for importing this method are org.hamcrest.MatcherAssert.assertThat and org.junit.Assert.assertThat, neither of which have a single-argument assertThat method as is being used in this Robolectric test.
My app's build.gradle has these dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
testCompile "org.robolectric:robolectric:3.0"
testCompile 'junit:junit:4.12'
}
What framework/library is this test using?
It is neither junit or hamcrest assertion API. I think it is Android AssertJ or just AssertJ:
testCompile 'org.assertj:assertj-core:1.7.1'
follow the following and the issue should go away. Put the first line in you gradle build file
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'junit:junit:4.12'
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
public class SomethingTest {
#Test
public void testSomething() {
assertThat(true, 1>1);
}
}
this link should provide more details also
Android Studio and Robolectric
I have been trying relentlessly to use this library. Everytime I add it, I lose all android.support.v4 and com.google.android.gms.maps cababilities. There is very little documentation for this library.
Is there any tutorial that I have overlooked in my extensive Google searching?
Here's my gradle file:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.androidmapsextensions:android-maps-extensions:2.2.0'
}
Also, I was using the raw code. Just found a jar on the net. Should I be using that instead?
what conflict you that you are using two dependencies with common function
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.androidmapsextensions:android-maps-extensions:2.2.0'
when you using it in your application make sure which library imported
example
you try use GoogleMap
you have two options in import
import com.google.android.gms.maps.GoogleMap;
**OR**
import com.androidmapsextensions.GoogleMap;
.........
...
private GoogleMap map;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// options instance from MarkerOptions
// choose map extensions if you want pass data by setData method
map.addMarker(options).setData(data);
}
Summary
Organize your imports as your need from google map libraries