Can't use android.support.v7.widget.Toolbar - java

private android.support.v7.widget.Toolbar toolbar; gives an error "Cannot resolve symbol v7" , i tried implementation in gradle but didn't work , please help
i will provide images and code bellow
TOOLBAR XML CODE
SOCIAL MEADIA CLASS XML
SOCIAL MEDIA JAVA CLASS
GRADLE DEPENDENCIES
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "com.github.parse-community.Parse-SDK-Android:parse:1.24.1"
implementation 'com.github.Shashank02051997:FancyToast-Android:0.1.6'
implementation 'com.android.support:design:+'
implementation 'com.android.support:appcompat-v7:29.0.3'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
XML CODE
?xml version="1.0" encoding="utf-8"?
android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/myToolbar"
android:background="#color/colorPrimaryDark"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
android.support.v7.widget.Toolbar
JAVA CLASS
public class SocialMediaActivity extends AppCompatActivity {
private android.support.v7.widget.Toolbar toolbar;
private ViewPager viewPager;
private TableLayout tableLayout;
private TabAdapter tabAdapter;
public SocialMediaActivity() {
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_social_media);
}
}

The v7 support library does not appear in your dependencies in your gradle file. The v7 support library has been deprecated. You should use androidx.appcompat.widget.Toolbar. See: https://developer.android.com/jetpack/androidx. You have the dependency androidx.appcompat:appcompat:1.1.0 in your gradle file, so you'll have access to the androidx toolbar.

While using androidX you need to use androidx.appcompat.widget.Toolbar for toolbar. And add implementation 'androidx.appcompat:appcompat:1.1.0' to app level gradle file.

Related

ActivitySplitLayoutBinding is unresolved; what is the required library?

I try to implement the code described in the "java with callbacks" section of the document in https://developer.android.com/guide/topics/large-screens/make-apps-fold-aware.
But ActivitySplitLayoutBinding is unresolved.
Here is an extract of my build.gradle file:
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.core:core:1.7.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation "androidx.window:window:1.0.0"
implementation "androidx.window:window-java:1.0.0"
implementation "androidx.window:window-rxjava2:1.0.0"
implementation 'androidx.startup:startup-runtime:1.1.1'
implementation 'androidx.navigation:navigation-fragment:2.4.1'
implementation 'androidx.navigation:navigation-ui:2.4.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0'
implementation 'com.opencsv:opencsv:5.0'
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
What am I missing?
ActivitySplitLayoutBinding is not coming from any library but is just a view bindings definition linked to a xml layout.
E.g. in this sample, there will be a .xml named activity_split_layout.xml when you use ViewBindings, then you will have a definition named ActivitySplitLayoutBinding in your Activity class, so you can access to all its views from the layout.
You can learn more about ViewBindings here: https://developer.android.com/topic/libraries/view-binding
Hope that this helps.
-Cesar

Android ClassCircularityError

I get ClassCircularityError when my app launch. It seems to appear after I added
implementation 'com.google.android.play:core:1.6.5'
to my app level gradle file. Here is my stacktrace:
Fatal Exception: java.lang.ClassCircularityError: Class byte extends itself (declaration of 'byte' appears in base.apk!classes3.dex)
at dalvik.system.DexFile.defineClassNative(DexFile.java)
at dalvik.system.DexFile.defineClass(DexFile.java:282)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:275)
at dalvik.system.DexPathList$Element.findClass(DexPathList.java:677)
at dalvik.system.DexPathList.findClass(DexPathList.java:466)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:123)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
Crash appears on this piece of code:
public void onCreate() {
super.onCreate();
.......................
db = Room.databaseBuilder(getApplicationContext(),
AppDatabase.class, "database-name")
.fallbackToDestructiveMigration()
.build(); // on this line
.............................
Also it appears in another place, just in first line of launching activity onCreate() method.
Here is my whole dependency list:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// Required for local unit tests (JUnit 4 framework)
implementation "com.android.support:support-v4:28.0.0"
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.17.0'
//Room
implementation "android.arch.persistence.room:runtime:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
// Required for instrumented tests
androidTestImplementation "com.android.support:support-annotations:$supportVersion"
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.afollestad.material-dialogs:core:0.9.5.0'
//social networks
implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
//support libs
implementation 'com.android.support:multidex:1.0.3'
implementation "com.android.support:appcompat-v7:28.0.0"
implementation "com.android.support:cardview-v7:28.0.0"
implementation "com.android.support:customtabs:28.0.0"
implementation "com.android.support:recyclerview-v7:28.0.0"
implementation "com.android.support:design:28.0.0"
implementation "com.android.support:percent:28.0.0"
//google libs
implementation "com.google.firebase:firebase-messaging:17.4.0"
implementation "com.google.firebase:firebase-core:16.0.7"
implementation "com.google.android.gms:play-services-location:$googleVersion"
implementation 'com.google.android.play:core:1.6.5'
//cupboard
implementation 'nl.qbusict:cupboard:2.2.0'
implementation 'nl.littlerobots.cupboard-tools:gson:0.3.1'
implementation 'com.github.smart-fun:XmlToJson:1.4.4'
//rest
implementation 'com.squareup.retrofit:retrofit:1.9.0'
implementation 'com.squareup.okhttp:okhttp:2.7.0'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.5.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.1'
//MVP
implementation "com.arello-mobile:moxy:$moxyVersion"
implementation "com.arello-mobile:moxy-app-compat:$moxyVersion"
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"
//butter
implementation "com.jakewharton:butterknife:$butterKnifeVersion"
kapt "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
//animation
implementation 'com.andkulikov:transitionseverywhere:1.7.6'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'joda-time:joda-time:2.9.9'
implementation 'com.romandanylyk:pageindicatorview:0.2.0'
implementation 'com.github.markomilos:paginate:0.5.1'
implementation 'com.splunk.mint:mint:5.0.0'
implementation 'androidmads.library.qrgenearator:QRGenearator:1.0.3'
implementation group: 'com.jakewharton.rxrelay', name: 'rxrelay', version: '1.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation('com.journeyapps:zxing-android-embedded:3.6.0') { transitive = false }
implementation 'com.journeyapps:zxing-android-embedded:3.2.0#aar'
implementation 'me.relex:circleindicator:1.2.2#aar'
implementation 'com.birbit:android-priority-jobqueue:2.0.1'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.github.jakob-grabner:Circle-Progress-View:v1.3'
implementation 'com.github.javiersantos:BottomDialogs:1.2.1'
implementation 'com.github.zcweng:switch-button:0.0.3#aar'
implementation 'jp.wasabeef:blurry:2.1.1'
implementation 'co.infinum:goldfinger:1.1.1'
implementation 'co.infinum:goldfinger-rx:1.1.1'
implementation "android.arch.work:work-runtime:1.0.1"
implementation "ru.tinkoff.decoro:decoro:1.3.4"
implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.github.GoodieBag:Pinview:v1.3'
implementation 'com.beust:klaxon:3.0.1'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.2.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1#aar') {
transitive = true
}
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation project(':bottom-navigation-bar-release')
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.squareup.whorlwind:whorlwind:2.0.0'
implementation 'com.google.maps.android:android-maps-utils:0.4.4'
implementation 'com.bartoszlipinski:recyclerviewheader2:2.0.1'
implementation group: 'org.simpleframework', name: 'simple-xml', version: '2.7'
//App icon badge related library dependency
implementation "me.leolin:ShortcutBadger:1.1.22#aar"
implementation 'com.thoughtbot:expandablecheckrecyclerview:1.4'
// Range seekbar library dependency
compile 'com.crystal:crystalrangeseekbar:1.1.3'
implementation 'android.arch.persistence.room:rxjava2:1.1.1'
// Date and Time picker dialog
implementation 'com.github.florent37:SingleDateAndTimePicker:v2.0.4'
}

Why don't I get my Google account with AccountManager?

I want to make a request for my Android application to display a Google Tasks task (in an AsyncTask).
public class TacheAsyncTask extends AsyncTask<Void, Void, String> {
private AsyncResponse delegate;
private Activity mActivity;
TacheAsyncTask(AsyncResponse asyncResponse, Activity activity) {
this.delegate = asyncResponse;
this.mActivity = activity;
}
#Override
protected String doInBackground(Void... params) {
AccountManager accountManager = AccountManager.get(mActivity);
Account myAccount = accountManager.getAccounts()[0];
}
With the AccountManager, I only get my Samsung account (length of the request = 1), so I have no access to Google Tasks.
In my Manifest :
<uses-permission android:name="android.permission.READ_CALENDAR"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android:permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.samsung.android.app.notes.READ"/>
In my build.gradle (app) :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'pub.devrel:easypermissions:2.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.api-client:google-api-client:1.25.0'
implementation 'com.google.apis:google-api-services-oauth2:v1-rev155-1.25.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
implementation 'com.google.apis:google-api-services-tasks:v1-rev49-1.23.0'
implementation 'com.google.api-client:google-api-client-jackson2:1.25.0'
}
I am running into the same issue, and just posted a similar question on here.
I suspect that it is due to this issue which affects all Android devices running Oreo.
As described there you must use GoogleAuthUtil.requestGoogleAccountsAccess to get the list of Google accounts. Unfortunately that requires a non-blocking call to the service, and then using the completion of the background thread to trigger the Google account retrievals, which I am currently trying to work into my program.

Importing GraphStream library in Android Studio

I've imported the gs-ui-android and gs-core-2.0-alpha modules and they are reflected in the settings.gradle as well. Also included these in gradle app module
implementation files(':gs-ui-android')
implementation files(':gs-core-2.0-alpha')
Also included import statements
import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
I still get an error in this code
error: package org.graphstream.graph does not exist error: package
org.graphstream.graph.implementations does not exist error: cannot
find symbol class SingleGraph error: incompatible types: String cannot
be converted to Node error: cannot find symbol class Viewer
Code Sample:
Graph graph1 = new SingleGraph("I can see dead pixels");
graph1.addNode("A" );
graph1.addNode("B" );
graph1.addNode("C" );
graph1.addEdge("AB", "A", "B");
graph1.addEdge("BC", "B", "C");
graph1.addEdge("CA", "C", "A");
Viewer viewer = graph1.display();
Build.gradle(app module):
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'io.particle:devicesetup:0.4.9'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.github.john990:WaveView:v0.9'
implementation 'org.giwi:android-network-graph:0.0.1'
// implementation 'guru.nidi:graphviz-java:0.2.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:multidex:1.0.3'
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
// implementation files(':gs-ui-android')
// implementation files(':gs-core-2.0-alpha')
}
repositories {
mavenCentral()
}
You can use jitpack to import github projects
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Then you can put the links to the desired version
dependencies {
api 'com.github.graphstream:gs-ui-android:2.0-alpha'
api 'com.github.graphstream:gs-core:2.0-alpha'
}
Here you can see an example
https://github.com/graphstream/gs-ui-android-test

Android ButterKnife

I've installed ButterKnife my build.gradle looks like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.jakewharton:butterknife:8.4.0'
}
My loginActivity looks like this:
package com.example.egen.forum;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class LoginActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
Toast.makeText(getApplicationContext(), "Your toast message.",
Toast.LENGTH_SHORT).show();
}
#OnClick(R.id.btnLogin) public void test() {
Toast.makeText(getApplicationContext(), "Your toast message.",
Toast.LENGTH_SHORT).show();
}
}
The second toast does not show up. What am I doing wrong here?
You haven't included annotation processor for ButterKnife code generation. Do it like described on the GitHub page:
dependencies {
compile 'com.jakewharton:butterknife:8.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
}
And apply the plugin:
apply plugin: 'com.jakewharton.butterknife'
Otherwise, your code looks fine.
Explanation: ButterKnife library uses annotation processor for generating the code that provides the references to views and executes ButterKnife annotated methods. If you rebuild your project, and the AndroidStudio shows that the #OnClick annotated method is unused, then somethings wrong. If the annotation processor is provided and works correctly, it should show as used and lead to a generated method.
Add this line:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
as well in your build.gradle.
See here for more info
Well, Butterknife is yesterday, use databinding instead: https://developer.android.com/topic/libraries/data-binding/index.html.
This is almost the same tool out of the box

Categories