question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configuration advice for project using dynamic feature modules?

See original GitHub issue

I have an Android project which consists of an app module, a core module, and multiple dynamic feature modules. Each feature module defines its own .sq files.

The problem is that currently SQLDelight generates multiple Database classes: one for each module independently. These classes only contain the queries for their own module.

Is it possible to make SQLDelight generate a single Database class only in the core module, and make sure that this class contains the queries defined in every feature module?

I want to define my DI components for the database in the core module, so that they can be shared by all feature modules.

Here’s what the current project structure looks like:

├── app
├── core
├── features
│   ├── feature1
│   │   └── src
│   │       └── main
│   │           ├── java
|   │           └── sqldelight
│   │               └── com.example.myapp.feature1
│   │                           └── feature1.sq
│   ├── feature2
│   │   └── src
│   │       └── main
│   │           ├── java
|   │           └── sqldelight
│   │               └── com.example.myapp.feature2
│   │                           └── feature2.sq

I have tried defining the following configuration in every feature module’s build.gradle file, but to no avail:

sqldelight {
    Database {
        packageName = "com.example.myapp.core"
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
haroldadmincommented, Dec 15, 2019

@mhernand40 Happy to report that the method you suggested does work. Thanks for helping me out!

For people who might see this issue in the future, this is what my current project structure looks like:

- app
  - database
    - feature1
    - feature2

The app module depends on database which in turn depends on feature1 and feature2. Each module defines its own .sq files. The build.gradle files look like this:

// database/build.gradle

sqldelight {
  MyDatabase {
    packageName = "com.example.modularsqldelight.database"
    dependency project(":feature1")
    dependency project(":feature2")
  }
}

// feature1/build.gradle
sqldelight {
  MyDatabase {
    packageName = "com.example.modularsqldelight.feature1"
  }
}

// feature2/build.gradle
sqldelight {
  MyDatabase {
    packageName = "com.example.modularsqldelight.feature2"
  }
}

The result is that SQLDelight generates a MyDatabase class in the database module inheriting from MyDatabase0 and MyDatabase1 (auto-generated names for databases from the feature modules). The queries of both feature modules are therefore accessible from this class.

One caveat I found here was that if the database module does not contain any .sq files of its own then SQLDelight does not generate any code for it. I expected that it would contain an empty Database class inheriting from the ones defined in both feature modules.

0reactions
russhwolfcommented, Feb 13, 2020

@AlecStrong @haroldadmin Was there ever a bug filed for not generating code in a module with no .sq files? Couldn’t find it searching but I’d like to follow it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Overview of Play Feature Delivery | Android Developers
Installing 50 or more feature modules on a single device, via conditional or on-demand delivery, might lead to performance issues. Install-time modules, which ......
Read more >
Android Dynamic Feature Modules : The Future - Medium
Dynamic feature modules allow you to separate certain features and resources from the base module of your app and include them in your...
Read more >
Developing your own Dynamic Feature - ProAndroidDev
The main objective is creating a simple application with a Dynamic Feature Module which will be manually downloaded by the user. This scenario ......
Read more >
Best practices for a modularized app with dynamic features
Leo Chu / LINE□ Session OverviewLINE Android Client App has over 2.2 million LINEs of source code including all modules.
Read more >
Base project not found in dynamic feature module error
In the project we are planning to implement dynamic feature module. As part of project configuration I have followed all the steps mentioned ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found