error: package android.support.v7.app does not exist Problem - java

I keep getting such an error, what's wrong? and Have another problem?
This gives the first three red-shaped bugs!
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppcompatActivity;
import android.support.annotation.IdRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar
;
I am new to android development, and I have been using the command line tools to create an android project. I followed all the instructions given in the tutorial at android developers. However, they are focused more on IDE users.
findbugs {
sourceSets = []
ignoreFailures = false
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "video.compress.optimizasyon"
minSdkVersion 19
targetSdkVersion 29
versionCode 20
versionName "0.20"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable "GoogleAppIndexingWarning"
disable "MissingTranslation"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
// ACRA depends on Java 8
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.browser:browser:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.crystal:crystalrangeseekbar:1.1.3'
implementation 'commons-io:commons-io:2.6'
implementation group: 'com.google.guava', name: 'guava', version: '24.1-jre'
implementation 'com.nononsenseapps:filepicker:4.2.1'
implementation 'com.simplecityapps:recyclerview-fastscroll:1.0.18'
implementation group: 'org.javatuples', name: 'javatuples', version: '1.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.8'
implementation 'ch.acra:acra:4.11'
implementation 'com.google.android.gms:play-services-ads:18.2.0'
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
}

You are using androidx libraries.
Remove this dependency, since you are using the Material Components library:
implementation 'com.android.support:appcompat-v7:27.0.0'
Then change these classes (code and layout):
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppcompatActivity;
import android.support.annotation.IdRes;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar
to
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.annotation.IdRes;
import androidx.appcompat.app.ActionBar;
//import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar
Here the full class mapping.

Related

Error with implementing OpenBeans openbeans-1.0.jar

My project is in Java on android studio on IntelliJ.
I downloaded openbeans-1.0.jar, put it in my libs folder, went to Project Structure, and added it to the dependencies. Here is my build.gradle (:app) code:
apply plugin: 'com.android.application'
apply plugin: 'com.android.application'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.gotimejavaversion"
minSdkVersion 15
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.coordinatorlayout:coordinatorlayout:1.1.0'
implementation 'com.google.android.material:material:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.opencsv:opencsv:5.2'
implementation 'com.googlecode:openbeans:1.0'
implementation 'com.univocity:univocity-parsers:2.9.0'
}
This is the MVN Repository info I found online for OpenBeans using gradle(this is just a visual reference I am using to create the line implementation 'com.googlecode:openbeans:1.0' in my build.gradle file. I am not using Maven):
// https://mvnrepository.com/artifact/com.googlecode/openbeans
compile group: 'com.googlecode', name: 'openbeans', version: '1.0'
I get the error:
Could not determine the dependencies of task ':app:compileDebugRenderscript'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not find com.googlecode:openbeans:1.0.
Required by:
project :app
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I couldn't make out what I am doing wrong in the documentation. I've checked how I've typed it in multiple times and have tried implementation 'com.googlecode.openbeans:openbeans:1.0' I'm new to working with repositories and programming at that. Any help is appreciated.
Thank you!

error: package android.support.v7.app does not exist

i'm going to integrate firebase to my android project, but after following the tutorial i found that this error showing up
error: package android.support.v7.app does not exist.
i tried to clean the project,and i checked update in android .
this is my build.gradle [module ]
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
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:design:28.0.0'
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.android.gms:play-services-auth:17.0.0'
}
and this my build.gradle [ project ]
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
please help to solve this problem i spent all this day looking for a solution . thank you
For latest version (3.4 or higher) of Android Studio
Instead of
import android.support.v7.app.AppcompatActivity
Use this
import androidx.appcompat.app.AppcompatActivity
In MainActivity.java or in main java file
I think you should Migrate to AndroidX if you want to use 'com.google.android.gms:play-services-auth:17.0.0' (17.0.0 version) or if you don't want to migrate androdiX use version 16.0.0 implementation 'com.google.android.gms:play-services-auth:16.0.0'
The c in AppcompatActivity must be in uppercase:
import androidx.appcompat.app.AppCompatActivity

AppCompatActivity library not found with Sdk Version 28

I'm creating a new android project with SDK 28 when project finished to create I have an error in MainActivity.
I tried some methods:
Clean project
Clean Android Studio cache
Clean Gradle cache
Re-installed IDE
File-> Invalidate cache/restart
Remove .idea folder
Restart Android Studio.
Android Studio About:
Android Studio 3.3.2
Build #AI-182.5107.16.33.5314842, built on February 15, 2019
JRE: 1.8.0_152-release-1248-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.israteneda.myapplicationtest2"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
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'
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'
}
MainActivity.java
package com.israteneda.myapplicationtest2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
The error showed is:
Android resource linking failed
error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.israteneda.horariu:style/Theme.AppCompat.Light.DarkActionBar) not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:173: error: style attribute 'attr/colorPrimary (aka com.israteneda.horariu:attr/colorPrimary)' not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:174: error: style attribute 'attr/colorPrimaryDark (aka com.israteneda.horariu:attr/colorPrimaryDark)' not found.
D:\israt\android_apps\HorariU\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:175: error: style attribute 'attr/colorAccent (aka com.israteneda.horariu:attr/colorAccent)' not found.
error: failed linking references.
When I change the SDK to 27 the MainActivity works.
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.israteneda.horariu"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}
MainActivity.java
package com.israteneda.myapplicationtest2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Also works with androidx library.
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.israteneda.myapplicationtest"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
MainACtivity.java
package com.israteneda.myapplicationtest;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I expect to create an android project without problems, but the actual output is an error with AppCompatActivity on MainActivity. Why does this problem happen?
I got the same issue and solved it by updating Android Studio
1.Go to your project directory (or to Project View)
2.Find and open .idea directory
3.Remove caches and libraries directories
4.Invalidate Caches / Restart
The problem was solved by updating the new version of android studio 3.4, without importing the settings of the previus version.

Gradle: Error: Program type already present: javax.inject.Inject

I'm pretty new to Android Studios and Gradle, so if this question is something obvious I'd like to apologize.
I get the following error with the given code:
Error: Program type already present: javax.inject.Inject
apply plugin: 'com.android.application'
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.xxx.cryptoapp"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'android.arch.lifecycle:extensions:1.1.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'
compile 'com.lucadev:coinmarketcap-api:2.1'
}
I hope you can help me out. :)
Edit
I looked into the dependencies and saw that javax.inject is used two times:
//short version of the list
+--- org.glassfish.hk2.external:javax.inject:2.5.0-b42#jar
+--- com.fasterxml.jackson.core:jackson-core:2.8.4#jar
\--- javax.inject:javax.inject:1#jar
However I can't quite understand how I exclude the correct module..
assuming this is coming from a .jar file in the libs directory; it can be excluded alike this:
implementation (fileTree(dir: "libs", include: ["*.jar"])) {
exclude group: "javax.inject", module: "javax.inject"
}
while actually, the .jar should probably be just deleted and replaced with:
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
implementation ("com.fasterxml.jackson.core:jackson-core:2.9.8") {
exclude group: "javax.inject", module: "javax.inject"
}
the repository for this is mavenCentral().

Android studio : com.google.android.gms.internal.zzbgl not found

So i was going through many stackoverflow answers and i tried applying them on my code, but i still couldn't find fix for this error. Also this error happens only when i try to Run the app only. i can build the project without any issues.
So this is the error i'm getting.
error: cannot access zzbgl class file for com.google.android.gms.internal.zzbgl not found
Also after that i'm getting this as a warning
D:\FinalProject\app\src\main\java\com\example\www\mytaxiapp\Welcome.java:
uses or overrides a deprecated API.
Recompile with -Xlint:deprecation for details.
So far i tried changing the versions and commenting, also adding and removing dependencies, but still i was unable to find a solution for this. hope someone can help me here.
This is my gradle APP level file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.www.mytaxiapp"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.firebase:geofire-android:2.1.2'
implementation 'com.github.d-max:spots-dialog:0.7#aar'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.gms:play-services-location:12.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.firebase:firebase-core:16.0.1'
implementation 'com.android.support:design:27.1.0'
//Add Library
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.android.support:design:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
My Welcome.class file imports
package com.example.www.mytaxiapp;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.widget.Toast;
import com.firebase.geofire.GeoFire;
import com.firebase.geofire.GeoLocation;
import com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Welcome extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener
{
Updating location service did the work for me ;)
implementation 'com.google.android.gms:play-services-location:15.0.1'
Google GMS is a very large dependency. You could try to enable multidex (by adding following line to your defaultConfig:
defaultConfig {
...
multiDexEnabled true
...
}
If you are targeting lower Android-versions, it can be, that you need to include support-Multidex as a dependency:
implementation 'com.android.support:multidex:1.0.3'
In this case, you should add a Application-class whilst you overwrite attachBaseContext like this:
#Override
protected void attachBaseContext(Context base) {
MultiDex.install(this);
super.attachBaseContext(base);
}
Please don't forget the clear project and gradle-sync.
Hope that helps.

Categories