简体   繁体   中英

Android build flavor sqlite database

I'd like to create a demo from my application, so I tried to build another flavor, but if I try to run it, I get this exception: attempt to write a readonly database (code 1032)

Original Gradle

defaultConfig {
        minSdkVersion 9
        targetSdkVersion 24
        applicationId 'com.myapp.foo'
        versionCode 518
        versionName '4.3.2'
    }

and this is my gradle with the two flavors

   defaultConfig {
        minSdkVersion 9
        targetSdkVersion 24
    }
productFlavors {
    baz {
        applicationId 'com.myapp.baz'
        versionCode 1
        versionName '1.0.0'
    }
    foo {
        applicationId 'com.myapp.foo'
        versionCode 518
        versionName '4.3.2'
    }
}

Are you sure you have your flavor specific source segmented correctly so that you only have one SQLiteOpenHelper? Meaning you have one under src/baz/java and one under src/foo/java but not one under src/main/java? Or just a single one under src/main/java?

In your AndroidManifest.xml provider section, it should be like the below one.

<provider
        android:name="com.zoho.invoice.provider.ZInvoiceProvider"
        android:authorities="${applicationId}"
        android:writePermission="${applicationId}.permission.WRITE_SCHEDULE" />

So that the appropriate application id will be replaced while build process.

Also, in your whole project where ever, you use your application id, should be replace with the placeholder.

In your Java file, it can be accessed as

BuildConfig.APPLICATION_ID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM