rmaprojects/MyQoran-Compose

App crashes at start

Opened this issue · 9 comments

Dear sir, this app is very valuable. But it crashes at start. It says,

"java.lang.IllegalArgumentException: Expected URL scheme 'http' or 'https' but no scheme was found for null"

Could you please have a look at it? Thanks in advance.

Of course it crashes. Because you built it from it's sourcecode. The URL scheme mentioned is hidden.
If you take a look at the Injection Section:

@Provides
@Singleton
fun provideApiConfig(): ApiInterface {
     //....
     return Retrofit.Builder()
         .baseUrl(BuildConfig.API_BASE_URL) // This line
         .client(client)
         .addConverterFactory(GsonConverterFactory.create())
         .build()
         .create(ApiInterface::class.java)
}

The BuildConfig.API_BASE_URL contains nothing. It originates from build.gradle section that grabbed the URL from local.properties:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.dagger.hilt.android'
    id 'com.google.devtools.ksp'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.firebase.firebase-perf'
}

android {
    namespace 'com.rmaproject.myqoran'
    compileSdk 34

    defaultConfig {
      //...
        
       // These lines:
        Properties properties = new Properties()
      // It grabbed local.properties. local.properties file is in my local machine which is secret
        properties.load(project.rootProject.file("local.properties").newDataInputStream())

        buildConfigField "String", "AUDIO_BASE_URL", "\"${properties.getProperty("AUDIO_BASE_URL")}\""
        buildConfigField "String", "NOTIFICATION_ICON_URL", "\"${properties.getProperty("NOTIFICATION_ICON_URL")}\""
        buildConfigField "String", "API_BASE_URL", "\"${properties.getProperty("API_BASE_URL")}\""
        buildConfigField "String", "QIBLA_FINDER_URL_ID", "\"${properties.getProperty("QIBLA_FINDER_URL_ID")}\""
        buildConfigField "String", "QIBLA_FINDER_URL_EN", "\"${properties.getProperty("QIBLA_FINDER_URL_EN")}\""
    }

   //...
}

If you want to try my app you can find my app on Google Play Store

Well, If you use the same Framework as Mine (Jetpack Compose) you can easily transfer/copy. my code to your own. If you are still using the old way to create Android Apps (with Views XML) you have to migrate or build it from start again using Jetpack Compose. You can always start your new Android Jetpack Compose project from Android Studio. Just update it into the latest version (iguana) and select the "Empty Activity"


Screenshot 2024-04-08 at 09 07 26

@DrMiaji IIRC, My app doesn't have any UPDATE function for Qur'an, how can you update the Qur'an 😅? The database functions are only for retrieving ayahs and sorahs, so no UPDATE option for Qur'an. And yes, you can mention me as RMA Projects as the name of the Developer. May Allah bless you for your efforts

Dear brother, after working on it for several weeks, now I have found the issue and resolved it.

I removed the @DatabaseView("SELECT id, sora, sora_name_ar, sora_name_en, sora_name_id, COUNT(id) as ayah_total, sora_descend_place FROM quran GROUP by sora") to the QoranDao.

The secone thing I changed is AppModule file and QoranDatabse files.

In AppModule file I kept only following:
@provides
@singleton
fun provideQuranDatabase(app: Application): QuranDatabase {
return QuranDatabase.getInstance(app)
}

In QoranDatabse file I added the following:

@database(
version = 5, entities = [Quran::class],
// views = [Surah::class, Juz::class, Page::class, Surah::class],

exportSchema = true, 

)
abstract class QuranDatabase : RoomDatabase() {
abstract fun quranDao(): QuranDao

companion object {
    @Volatile
    private var INSTANCE: QuranDatabase? = null
    fun getInstance(context: Context): QuranDatabase {
        return INSTANCE ?: synchronized(this) {
            INSTANCE ?: Room.databaseBuilder(
                context,
                QuranDatabase::class.java,
                "qoran.db"
            ).createFromInputStream {
                context.resources.openRawResource(R.raw.qoran)
            }
                .fallbackToDestructiveMigration()                 
                .build()
        }
    }
}

}

.fallbackToDestructiveMigration() is now working fine to delete the old database and add the new one. I am still working on it to make it work with Search functions so that both surah and ayah search are in the same location. If you have any update please let me know.