I'm new in Kotlin, i want to create an android mobile app.I use Android studio 3.3,the Android API level 28. I have used a swagger to get all my RESTful web service, thus, i have the android-client-generated the file that contains all the web service. As a start, I created an android interface for authentication with Email and Password". Among the web service available, "apiMobileUsersGetByFireBaseIDGet". This Ws, use the firebase Id to authenticate. I create a kotlin class AUthentication as the following
class Authentication : AppCompatActivity() {
var fireBaseAuthentication = FirebaseAuth.getInstance()
private var mobileApi: MobileApi? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
JodaTimeAndroid.init(this)
setContentView(R.layout.activity_authentication)
mobileApi = MobileApi()
buttonLogin.setOnClickListener {
signIn(editTextEmail.text.toString(), editTextPassword.text.toString())
}
txtViewSignUp.setOnClickListener {
var intent = Intent(this, Register::class.java)
startActivity(intent)
overridePendingTransition(R.anim.slide_right_in, R.anim.slide_left_out)
}
}
private fun verifyAvailableNetwork(activity: AppCompatActivity): Boolean {
val connectivityManager = activity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectivityManager.activeNetworkInfo
return networkInfo != null && networkInfo.isConnected
}
private fun signIn(email: String, password: String) {
showMessage("Authenticating...")
fireBaseAuthentication.signInWithEmailAndPassword(email, password).addOnCompleteListener { task ->
if (task.isSuccessful) {
GlobalScope.launch(Dispatchers.IO) {
val user = fireBaseAuthentication.currentUser?.uid?.let { mobileApi!!.apiMobileUsersGetByFireBaseIDGet(it) }//////////////////////
withContext(Dispatchers.Main) {
println(user!!.fireBaseID)
println(user!!.email)
var intent = Intent(this@Authentication, MainActivity::class.java)
intent.apply {
putExtra("id", user.fireBaseID)
putExtra("email", user.email)*/
}
startActivity(intent)
}
}
} else {
showMessage("Error: ${task.exception?.message}")
}
}
}
private fun showMessage(message: String) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show()
}
i added alse the internet permission in the AndroidManifest.xml. My problem is when i run my app in my mobile phone, an error. I tried to use the ThreeTenABP library and jodatime library but the error still persist java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime", the error is ddescribe as the following
E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: com.app.app, PID: 19319
java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/com.app.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.app.appt-1/lib/arm64, /vendor/lib64, /system/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.parseType(KDeclarationContainerImpl.kt:283)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.loadParameterTypes(KDeclarationContainerImpl.kt:274)
at kotlin.reflect.jvm.internal.KDeclarationContainerImpl.findConstructorBySignature(KDeclarationContainerImpl.kt:242)
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:65)
at kotlin.reflect.jvm.internal.KFunctionImpl$caller$2.invoke(KFunctionImpl.kt:34)
at kotlin.reflect.jvm.internal.ReflectProperties$LazySoftVal.invoke(ReflectProperties.java:92)
at kotlin.reflect.jvm.internal.ReflectProperties$Val.getValue(ReflectProperties.java:31)
at kotlin.reflect.jvm.internal.KFunctionImpl.getCaller(KFunctionImpl.kt)
at kotlin.reflect.jvm.ReflectJvmMapping.getJavaMethod(ReflectJvmMapping.kt:62)
at kotlin.reflect.jvm.KCallablesJvm.setAccessible(KCallablesJvm.kt:82)
at com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt:206)
at com.squareup.moshi.KotlinJsonAdapterFactory.create(KotlinJsonAdapter.kt)
at com.squareup.moshi.Moshi.adapter(Moshi.java:137)
at com.squareup.moshi.Moshi.adapter(Moshi.java:97)
at com.squareup.moshi.Moshi.adapter(Moshi.java:71)
at io.swagger.client.apis.MobileApi.apiMobileUsersGetByFireBaseIDGet(MobileApi.kt:4708)
at com.app.homecraft.ui.user.Authentication$signIn$1$1.invokeSuspend(Authentication.kt:88)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
Suppressed: java.lang.ClassNotFoundException: java.time.LocalDateTime
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 23 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available