Simple Firebase notification not working on Android - android

So, I've been trying for hours to make notification works but without success.
My goal is to send a notification from the Firebase console and receive it on the phone. This means that I should only add the library to my application and configure a project on Firebase.
In my app I'm already using firebase for storage, analytics and ads without problem.
I've followed the official tutorial and also this video
I've not added the service in the manifest because I don't need to do any particular message handling
This is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.myapp">
<activity android:name="com.domain.myapp.MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:requestLegacyExternalStorage="true"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/provider_paths"/>
</provider>
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="myid"/>
</application>
</manifest>
root level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.20"
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.5'
def nav_version = "2.3.4"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Application level build file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'androidx.navigation.safeargs.kotlin'
id 'kotlin-kapt'
id 'com.google.gms.google-services'
}
android {
signingConfigs {
release {
storeFile file('keystore')
storePassword 'psw'
keyAlias 'key0'
keyPassword 'psw'
}
}
compileSdkVersion 30
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.domain.myapp"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
def AD_UNIT_ID = "AD_UNIT_ID"
debug {
buildConfigField "String", AD_UNIT_ID, AD_UNIT_ID_TEST
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField "String", AD_UNIT_ID, AD_UNIT_ID_PROD
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.firebase:firebase-storage:19.2.1'
implementation 'com.google.firebase:firebase-messaging-ktx:21.0.1'
implementation 'com.google.firebase:firebase-analytics-ktx:18.0.2'
def nav_version = "2.3.4"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
implementation "androidx.navigation:navigation-compose:1.0.0-alpha09"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation("com.github.bumptech.glide:glide:4.12.0")
implementation("com.github.bumptech.glide:recyclerview-integration:4.11.0")
kapt 'com.github.bumptech.glide:compiler:4.12.0'
implementation 'com.firebaseui:firebase-ui-storage:7.1.1'
implementation 'com.github.smarteist:autoimageslider:1.4.0'
implementation 'com.google.android.gms:play-services-ads:19.8.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
This is my App class:
class App: Application() {
override fun onCreate() {
super.onCreate()
MobileAds.initialize(this)
}
}
And this is my main activity:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupAdViewInto(adContainer)
}
private fun setupAdViewInto(adContainer: LinearLayout, adSize: AdSize = SMART_BANNER) {
val adView = AdView(this)
adView.adSize = adSize
adView.adUnitId = AD_UNIT_ID
adContainer.addView(adView)
adView.loadAd(AdRequest.Builder().build())
}
}
On the firebase console I see this:
Note: I've tried crating a new app from scratch and to do the same operation and that it's working!

I got it working, but I don't know how... I'm thinking is Android Studio's fault.
I've done these steps
created a new project on firebase
downloaded and imported the new google-services.json
cleaned cache data and reinstalled the app on the emulator using the button Run 'app' from Android Studio
the app is still showing stuff from the old firebase application, like it's using the old google-services.json
deleted gradle's build folder from Android Studio
reinstalled the app as before using the old configuration
notifications are now working
WTF!??
I'm thinking that the problem was due to gralde/android studio.
I've lost like 5 hours on this... I love programming :) :)

Related

add collection to firestore with kotlin problems

I am trying to understand and use firebasefirestore from android studio with kotlin.
I have been following tutorials from the official docs, and from udemy and youtube. I do the exact same thing as shown, but still my collection is not created in the firestore console.
I want to add a collection to firestore from within android studio with kotlin.
To my understanding all my code is correct, I have internet permission, I have all the dependencies needed in my gradle files.
And my code for adding a collection to firebase is the exact same as given in the official docs.
Still no matter what I do, I can not create a collection from running my app.
I can create a firestore collection from within the firestore console without a problem.
My app runs and execute with out any errors (beside not creating the collection in firestore).
Here is my code
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.example.firestoretest">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.FireStoreTest">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="#string/app_name"
android:theme="#style/Theme.FireStoreTest">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Gradle project
buildscript {
ext {
compose_version = '1.0.1'
}
dependencies {
classpath 'com.google.gms:google-services:4.3.10'
}
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle module
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}
android {
compileSdk 31
defaultConfig {
applicationId "eu.example.firestoretest"
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation "androidx.compose.ui:ui:$compose_version"
implementation "androidx.compose.material:material:$compose_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.activity:activity-compose:1.3.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
// Firebase
implementation "com.google.firebase:firebase-auth:19.2.0"
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation "com.google.firebase:firebase-auth-ktx"
implementation "com.google.firebase:firebase-firestore-ktx"
implementation "com.google.firebase:firebase-storage-ktx"
implementation 'com.google.firebase:firebase-firestore:24.0.1'
implementation 'com.google.firebase:firebase-storage:20.0.0'
}
Creating a db
package eu.example.firestoretest
import android.util.Log
import androidx.compose.runtime.Composable
import com.google.firebase.firestore.ktx.firestore
import com.google.firebase.ktx.Firebase
#Composable
fun fireStoreTest(){
// Create a FirebaseFirestore object
val db = Firebase.firestore
// Pass data onto the firestore db, it must be of type hashmap
val user = hashMapOf(
"first" to "Ada",
"last" to "Lovelace",
"born" to 1815
)
// add the user data to the collection
db.collection("users")
.add(user)
.addOnSuccessListener {
Log.d("FB", "onCreate: ${it.id}")
}
.addOnFailureListener {
Log.d("FB", "onCreate: ${it}")
}
}
I then call the function fireStoreTest in my main function, but it doesn't work.
Is there someone who could explain in very simple terms what it is I am doing wrong ?
link to logcat
https://github.com/McCt68/logcat/blob/main/firestore_logcat.txt
I was also having similar issue where I was not able to add collection on Firestore from Android Studio. What worked for me is setting the rules of Firestore to this :
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if
request.time < timestamp.date(2022, 5, 3);
}
}
}

Build fails with 'task :features:catalog:createDebugCompatibleScreenManifests FAILED' while refactoring to dynamic feature modules on android

Once I introduced dynamic feature modules into my app, I was able to successfully refactor feature one (orders), build and deploy. But on refactoring the second module, i.e moving files and resources to that module, I get this error on build:
Execution failed for task ':features:catalog:createDebugCompatibleScreenManifests'.
> Failed to calculate the value of task ':features:catalog:createDebugCompatibleScreenManifests' property 'applicationId'.
> Failed to query the value of property 'testedApplicationId'.
> Collection has more than one element.
I have tried the following fixes:
invalidate cache
reclone project
ensure all gradle files are identical (except for applicationId bit)
checked that there are no errors in the manifest files
confirmed that no two modules share the same application ID.
rebase the project to the last working commit.
Any pointers as to what is causing this build issue?
Other info: I'm using dependency injection with koin.
App/Main module manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.app">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:name="android.hardware.camera2"
android:required="false" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:name=".ExampleApp"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:networkSecurityConfig="#xml/network_security_config"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data
android:name="firebase_crashlytics_collection_enabled"
android:value="${crashlyticsCollectionEnabled}" />
<activity android:name="com.kyosk.app.ui.fragment.login.LoginActivity" />
<activity android:name="com.kyosk.app.ui.activity.SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.kyosk.app.ui.activity.Home" />
<service
android:name=".service.MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name=".location.services.LocationUpdatesService"
android:exported="false" />
<service
android:name=".location.services.MapsLocationUpdatesService"
android:exported="false" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="#xml/file_paths" />
</provider>
</application>
</manifest>
App/Main module build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"
apply plugin: 'realm-android'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: (BuildPlugins.dependencyUpdateChecker)
android {
compileSdkVersion AndroidSDK.compileSDKVersion
buildToolsVersion Versions.buildTools
defaultConfig {
applicationId "com.example.app"
minSdkVersion AndroidSDK.minimumSDKVersion
targetSdkVersion AndroidSDK.targetSDKVersion
versionCode Versions.versionCode
versionName Versions.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
applicationIdSuffix(".debug")
versionNameSuffix("-debug")
buildConfigField("String", "BASE_URL", debug_url)
}
staging {
initWith(release)
manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
applicationIdSuffix(".staging")
versionNameSuffix("-staging")
buildConfigField("String", "BASE_URL", staging_url)
}
release {
manifestPlaceholders = [crashlyticsCollectionEnabled: "true"]
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
buildConfigField("String", "BASE_URL", production_url)
}
}
buildFeatures {
viewBinding = true
dataBinding = true
}
kotlinOptions {
jvmTarget = '1.8'
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kapt {
correctErrorTypes = true
}
dynamicFeatures = [':features:kiosks', ':features:catalog', ':features:checkout', ':features:summary', ':features:orders']
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation Libraries.kotlinStandardLibrary
implementation Libraries.appCompat
implementation Libraries.constraintLayout
api Libraries.materialComponents
implementation Libraries.navigationFragment
implementation Libraries.navigationUI
implementation Libraries.preferences
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
//firebase libs
implementation Libraries.firebaseMessaging
implementation Libraries.firebaseConfig
// Recommended: Add the Firebase SDK for Google Analytics.
implementation Libraries.firebaseAnalytics
implementation Libraries.firebaseCrashlytics
// DI
api Libraries.koinAndroid
api Libraries.koinLifecycle
api Libraries.koinViewmodel
//maps
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//own modules
implementation project(path: ':location-services')
implementation project(path: ':network')
api project(path: ':helpers')
//glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
//loading button
api Libraries.buttonProgress
//pagination lib
implementation Libraries.jdroidCoder
//EventBus
api Libraries.eventBus
//logging
api Libraries.timber
//anko
api Libraries.ankoDesign
api Libraries.ankoCommons
//play core library
implementation(Libraries.playCore)
implementation(Libraries.playCorektx)
// paris for applying styles to views dynamically
implementation 'com.airbnb.android:paris:1.7.2'
// lottie for animations
implementation 'com.airbnb.android:lottie:3.5.0'
// Okhttp Profiler
implementation Libraries.loggingInterceptor
// Test libs
testImplementation(TestLibraries.junit4)
androidTestImplementation(TestLibraries.androidX)
androidTestImplementation(TestLibraries.espresso)
androidTestImplementation(TestLibraries.annotationLib)
}
Feature Module 1(orders) manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.example.app.orders">
<dist:module
dist:instant="false"
dist:title="#string/title_orders">
<dist:delivery>
<dist:install-time />
</dist:delivery>
<dist:fusing dist:include="true" />
</dist:module>
</manifest>
Feature 1 (orders) build.gradle
apply plugin: 'com.android.dynamic-feature'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: (BuildPlugins.dependencyUpdateChecker)
android {
compileSdkVersion AndroidSDK.compileSDKVersion
buildToolsVersion Versions.buildTools
defaultConfig {
applicationId "com.example.app.orders"
minSdkVersion AndroidSDK.minimumSDKVersion
targetSdkVersion AndroidSDK.targetSDKVersion
versionCode Versions.versionCode
versionName Versions.versionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {}
staging {}
release {}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding = true
dataBinding = true
}
}
dependencies {
implementation project(":app")
implementation project(path: ':network')
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation Libraries.kotlinStandardLibrary
implementation Libraries.ktxCore
implementation Libraries.appCompat
implementation Libraries.constraintLayout
implementation Libraries.materialComponents
implementation Libraries.navigationFragment
implementation Libraries.navigationUI
implementation Libraries.buttonProgress
implementation Libraries.ankoDesign
implementation Libraries.ankoCommons
implementation(Libraries.coroutinesAndroid)
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
// Test libs
testImplementation(TestLibraries.junit4)
androidTestImplementation(TestLibraries.androidX)
androidTestImplementation(TestLibraries.espresso)
androidTestImplementation(TestLibraries.annotationLib)
}
The issue ended up being a library I had imported.
The library had plugin apply plugin: 'com.android.application'
instead of
apply plugin: 'com.android.library'
As such, gradle build task was looking for applicationId and applicationName in the manifest, which was not there.
Oops, developer error.
For me it happened when adding a new dynamic feature module with multiple flavors.
I solved it by changing inside module.gradle:
implementation project(path: ':app', configuration: 'default')
into
implementation project(":app")
Then add flavors into module.gradle
flavorDimensions "app"
productFlavors {
flavor1 {}
flavor2 {}
flavor3 {}
}
Here is my final module.gradle
apply plugin: 'com.android.dynamic-feature'
android {
compileSdkVersion 29
buildToolsVersion '29.0.3'
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
flavorDimensions "app"
productFlavors {
flavor1 {}
flavor2 {}
flavor3 {}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation project(":app")
}
Uninstall the application from emulator and then restart it

I can't see the elements by their id in Android Studio

I'm a new Kotlin Programmer. I tried to change the app icon by deleting the ic_launcher.png files and replacing my own images. As i see that is ridiculous what i'm trying to do, i copied the "Main Activity.kt" and "main_activity.xml" files and created a new project. As i tried to copy the files into the new project, the program throws a lot of errors:
It didn't imported the "kotlinx" packet and didn't perceive the elements in the xml file. As i tried to create an another new project to try whether the problem is only for this project, i realized that Android Studio doesn't perceive the xml elements anymore.
Here are some important infos about my project:
The Android Manifest XML File
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ihdovanay.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.MyApplication">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The Build Gradle File of The Project
buildscript {
ext.kotlin_version = "1.4.10"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
The Build Gradle File of the Module
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.ihdovanay.myapplication"
minSdkVersion 21
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'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
I would be very happy if you could solve my problem.
Revised answer after the deprecation of view synthetics.
You're missing the kotlin-android-extensions plugin in your build.gradle. It's responsible for generating synthetic view references.
kotlin-android-extensions is now deprecated, so it is no longer included by default and should no longer be added to projects. You should use findViewById or View Binding.
You can make it work by doing the following, but I don't recommend adding and relying on a deprecated library. Add the line to your plugins block at the top:
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
In Android Studio 4.1.1, the following code is missing in build.gradle (module: yourAppName)
id 'kotlin-android-extensions'

Unable to import parse in android studio

I am following back4app documentation for intalling parse sdk.Done everything what they said ,but my application class is unable to import "Parse".I visited old answers regarding this here (stackover flow) but none worked for me.
my build.gradle(module):--->
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.example.loginapp"
minSdkVersion 15
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.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
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:bolts-tasks:1.24.2'
}
build.gradle(app):--->
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android manifest:--->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.loginapp">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Application class:--->
package com.example.loginapp;
import com.parse.Parse;
import android.app.Application;
public class App extends Application {
// Initializes Parse SDK as soon as the application is created
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("fif7ynkG8j1YIhqHywgbHaCgT3rZod0fzMllv8fe")
.clientKey("wpZd5EqXOPFpxrx5uZYP3dwk38ZTjZWnPODAYThS")
.server("https://parseapi.back4app.com")
.build()
);
}
}
please help!
thankyou
You need to add this dependency:
implementation "com.github.parse-community.Parse-SDK-Android:parse:1.24.2"

Why don't the app run under Android 4.x in Kotlin?

There is a very simple app made by Kotlin, it can work well under Android 8.0, Android 6.0 and Android 5.1 in Android Studio 3.0
but I get the error message "java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{info.dodata.mirror/ui.UIMain}: java.lang.ClassNotFoundException: ui.UIMain" when I run the app under Android 4.1. 2 (This is a real mobile phone) and Android 4.2.2
You can test it by download the app at https://www.dropbox.com/s/9f0yxp5pqqxtcxq/Mirror.zip?dl=0
UIMain.kt
package ui
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import info.dodata.mirror.R
class UIMain : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.layout_main)
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.dodata.mirror">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name="ui.UIMain">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
build.gradle (Module:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
flavorDimensions "default"
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
applicationId "info.dodata.mirror"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.01"
archivesBaseName = "BackupSettings-V" + versionName
}
productFlavors {
free {
applicationId "info.dodata.mirror"
}
pro {
applicationId "info.dodata.mirror.pro"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "boolean", "IsDebugMode", "false"
}
debug {
buildConfigField "boolean", "IsDebugMode", "true"
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation "org.jetbrains.anko:anko-commons:$anko_version"
implementation "org.jetbrains.anko:anko-sqlite:$anko_version"
}
build.gradle (Top)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.51'
ext.anko_version = '0.10.2'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
On Android 5.0 and later, multiple .dex files are automatically loaded by ART together. However, on earlier Android versions, Dalvik starts the application with only the main classes.dex, and the application must load the secondary the .dex files before anything else is done.
This is handled by the multidex support library, but you did not follow the instructions. This means that some of your classes are not present when the system is trying to start your activity, leading to a crash.
Depending on whether you override the Application class, perform one of the following:
If you do not override the Application class, edit your manifest file to set android:name in the <application> tag as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:name="android.support.multidex.MultiDexApplication" >
...
</application>
</manifest>
If you do override the Application class, change it to extend MultiDexApplication (if possible) as follows:
public class MyApplication extends MultiDexApplication { ... }
Or if you do override the Application class but it's not possible to change the base class, then you can instead override the attachBaseContext() method and call MultiDex.install(this) to enable multidex:
public class MyApplication extends SomeOtherApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
You are currently not overriding Application, so you should follow the first case.

Categories

Resources