PLS HELP. I think android studio Gradle files or settings got disturbed may be when adding external jar libraries or when I tried to rename a package. Whenever I open new project or even an already finished project Im getting errors.
Even whem i open new project
BUILD FAILED in 24s
6 actionable tasks: 6 executed
ERROR: Manifest merger failed with multiple errors, see logs
in Mainactivity
cannot resolve activitycompat and appcompatactivity
package com.example.android1.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.android1.myapplication"
minSdkVersion 26
targetSdkVersion 29
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.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Layout xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/tv"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/tx01"
app:layout_constraintBottom_toBottomOf="#+id/tv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="go"
app:layout_constraintBottom_toBottomOf="#+id/tv"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
enter image description here
MainActivity Screenshot attached
Related
implementation is in the build.gradle but I'm still getting "Cannot resolve class com.hbb20.CountryCodePicker" in main activity
This is the build.gradle:
plugins {
id 'com.android.application'
}
android {
namespace 'com.example.assignment1'
compileSdk 33
defaultConfig {
applicationId "com.example.assignment1"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.hbb20:ccp:2.6.1'
}
This is the activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context=".MainActivity">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/ic_launcher_background"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:id="#+id/logo"/>
<com.hbb20.CountryCodePicker
android:layout_width="match_parent"
android:layout_height="50dp"
app:ccp_areaCodeDetectedCountry="true"
android:layout_centerInParen="true"
android:layout_marginleft="100dp"
android:layout_marginright="100dp"
android:id="#+id/contrycodePicker"
app:ccp_autoDetectCountry="true"
android:layout_above="#id/centerhorizontalline"/>
the <com.hbb20.countrycodepicker shows up as an error. I can't seem to find what the problem is
I am new to Android development and have been working through an Android development course online. The last lesson taught me how to use fragments. I was able to follow along with the lesson using the provided framework project file. However when I tried to implement the principles in my own project to practice the data binding wouldn't work. There are two errors. The last import gives the error: "unresolved reference: databinding", and then another error is "unresolved reference: FragmentLoginBinding". I have spent the last 5 hours combing through forum posts and documentation but I cannot find my error. Any help would be greatly appreciated thank you.
*Edit: There is no databinding file in my generated java project file
My code is as follows:
fragment_login.kt:
package com.example.project2019
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.example.project2019.databinding.FragmentLoginBinding
class fragment_login : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = DataBindingUtil.inflate<FragmentLoginBinding>(inflater,R.layout.fragment_login,container,false)
return binding.root
}
}
fragment_login.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical"
tools:context="com.example.project2019.fragment_login">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_blank_fragment"
android:layout_gravity="center_horizontal"
/>
<Button
android:id="#+id/loginbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Log In"
/>
</LinearLayout>
Build.Gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
dataBinding {
enabled = true
}
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.project2019"
minSdkVersion 19
targetSdkVersion 29
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 "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "com.google.android.material:material:$version_material"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
You have to enclose your fragment_login.xml with layout to work data binding
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="center_vertical"
tools:context="com.example.project2019.fragment_login">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_blank_fragment"
android:layout_gravity="center_horizontal" />
<Button
android:id="#+id/loginbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Log In" />
</LinearLayout>
</layout>
Try adding the following lines to the build.gradle file
buildFeatures {
viewBinding true
}
dataBinding.enabled=true
I'm trying to use a viewpager in my app which used androidX but it showed me an error ERROR: Failed to resolve: viewpager Affected Modules: app after added implementation 'android.viewpager:viewpager:1.0.0' and Gradle project sync. I searched a lot but not found any solution.please any help thanks in advance.here is xml file.
xml file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Favourites.FavouriteLinks">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread_inside"
app:popupTheme="#style/AppTheme.PopupOverlay"
tools:layout_conversion_absoluteHeight="56dp"
tools:layout_conversion_absoluteWidth="384dp" android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintVertical_bias="0.0">
<TextView
android:id="#+id/toolbar_title"
style="#style/TextAppearance.AppCompat.Widget.ActionBar.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="casual"
android:gravity="left"
android:text="Favourites Brochures"
android:textColor="#color/colorwhite"
android:textSize="18sp"
android:textStyle="bold"
tools:layout_conversion_absoluteHeight="28dp"
tools:layout_conversion_absoluteWidth="56dp"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="14dp"/>
</androidx.appcompat.widget.Toolbar>
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:tabSelectedTextColor="#android:color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="32dp"
app:layout_constraintTop_toTopOf="#+id/toolbar"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.04000002" android:id="#+id/tabLayout">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="21sp"
android:textStyle="bold"
android:text="tab2"
/>
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab1"
android:textSize="21sp"
android:textStyle="bold"
/>
</com.google.android.material.tabs.TabLayout>
<androidx.viewpager.widget.ViewPager
android:id="#+id/viewPager"
android:layout_width="match_parent"
android:layout_height="508dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.85"/>
</androidx.constraintlayout.widget.ConstraintLayout>
kotlin code
class FavouriteLinks : AppCompatActivity() {
//This is our viewPager
var viewPager: ViewPager? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_favourite_links)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayShowTitleEnabled(false)
viewPager = findViewById<ViewPager>(R.id.viewPager)
val pageAdapter = PageAdapter(supportFragmentManager, tabLayout.tabCount)
viewPager?.adapter = pageAdapter
}
}
gradle file
//noinspection GradleCompatible
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.nanotech.i_cardplatform"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//noinspection GradleCompatible
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-alpha1'
//RETROFIT ... NETWORK LIBRARY
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
// RETROFIT .. CONVERTER
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
// Logging
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
// Room dependencies
implementation 'androidx.room:room-runtime:2.0.0-alpha1'
kapt 'androidx.room:room-compiler:2.0.0-alpha1'
annotationProcessor 'androidx.room:room-compiler:2.0.0-alpha1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'androidx.viewpager:viewpager:1.0.0'
}
repositories {
mavenCentral()
}
Do not add viewPager library separately it's already included in
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
Failed to find style 'floatingActionButtonStyle' in current theme.
I even tried doing this in my style.xml
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="floatingActionButtonStyle">#style/Widget.Design.FloatingActionButton</item>
</style>
It did not work. I used Base.theme because of appcompat problem I was facing . My appcompat is - 'com.android.support:appcompat-v7:28.0.0-alpha1
Here is the XML file where error is shown:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".MainActivity">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:src="#drawable/ic_send"
android:id="#+id/fab"
android:tint="#android:color/white"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:fabSize="mini"
/>
<android.support.design.widget.TextInputLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_toLeftOf="#+id/fab"
android:layout_alignParentBottom="true"
android:layout_toStartOf="#+id/fab"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
>
<EditText
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message..."
android:inputType="text" />
</android.support.design.widget.TextInputLayout>
<ListView
android:id="#+id/list_of_message"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/fab"
android:dividerHeight="16dp"
android:divider="#android:color/transparent"
android:layout_marginBottom="16dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true">
</ListView>
</RelativeLayout>
Build.gradle(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.hp.chatapp"
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 fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
//add library
implementation 'com.android.support:design:27.1.1'
// implementation 'com.firebaseui:firebase-ui-database:4.1.0'
}
apply plugin: 'com.google.gms.google-services'
After all the comments this is what I came up to:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.hp.chatapp"
minSdkVersion 16
targetSdkVersion 27
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:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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'
//add library
implementation 'com.android.support:design:27.1.1'
// implementation 'com.firebaseui:firebase-ui-database:4.1.0'
// consider using implementation 'com.firebaseui:firebase-ui-database:3.1.1'
// see the question below
}
apply plugin: 'com.google.gms.google-services'
I suggest using compileSdkVersion and targetSdkVersion 27 because, as you noticed,
28.0.0-alpha1 doesnt support FloatingActionButton style.
and might also cause problems as it is in alpha version.
Question about firebase-ui-database here.
Extra: You can search for libraries here and see how many people are using it or the release date.
for round about 2 weeks from now, I receive an error message, whenever I try to preview an .xml design-file in my Android Studio Project. As I am relatively new to the whole topic I'd like to ask whether you have an answer.
The error message:
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.Toolbar
OR
Rendering Problems:
The following classes could not be found:
- android.support.v7.widget.CardView
One of the .xml files:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toolbar_tabs"
android:background="#color/primaryColor"
app:contentInsetStart="0dp"
app:contentInsetEnd="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VPlan App RC1"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="20sp"
android:layout_marginLeft="16dp"
android:fontFamily="sans-serif-medium"
android:id="#+id/textView7"
android:layout_marginStart="16dp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_refresh"
android:id="#+id/ic_refresh"/>
</RelativeLayout>
<com.astuetz.PagerSlidingTabStrip
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#color/primaryColor"
android:textColorPrimary="#color/white"
android:textSize="14sp"
android:id="#+id/tabs"
android:layout_marginTop="?attr/actionBarSize" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
Also as it might help, here's the build.gradle file where the support library is located.
The build.grade file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'com.nocomment.vplanehs'
minSdkVersion 10
targetSdkVersion 22
versionCode 16
versionName '0.8.5_RC1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':volley')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.9'
}
In this project we also use volley as well as libraries from ZXing's QR Code reader.
I'd be very thankful if someone could help me. Thank you in advance!