Giter VIP home page Giter VIP logo

kotlin-synthetic-multi-flavor-sample's Introduction

Android plugin kotlinx.android.synthetic cannot handle resources across multiple flavors

Issue

When using multiple flavors in an Android project you should be able to access product flavor views using the synthetic imports AND the project shluld be able to compile.

Using import kotlinx.android.synthetic.internal.activity_internal.* does not work when using more than one flavor. Using import kotlinx.android.synthetic.main.activity_internal.* still works if I move the resources.

For background I found this issue when adding another level of flavors. These imports work when there is only 1 level of product flavors.

Steps to Reproduce

  1. Setup multiple flavor levels in an Android project like and turn the Android experimental flag:

     androidExtensions {
         experimental = true
     }
    
     flavorDimensions "build_type", "destination"
     
     productFlavors {
         development {
             dimension "build_type"
         }
         alpha {
             dimension "build_type"
             applicationIdSuffix '.alpha'
         }
         beta {
             dimension "build_type"
             applicationIdSuffix '.beta'
         }
         production {
             dimension "build_type"
         }
     
         internal {
             dimension "destination"
             applicationIdSuffix '.internal'
         }
     
         store {
             dimension "destination"
         }
     }
    
  2. Create the necessary folder structure for the flavors

  3. Create code that is only used in a product lavor and try to import the synthetic views (notice how Android studio doesn't complain about the impport so everything seems fine):

     package com.leneau.syntheticexample
     
     import android.support.v7.app.AppCompatActivity
     import android.os.Bundle
     import android.widget.TextView
     import kotlinx.android.synthetic.internal.activity_internal.*
     
     class InternalActivity : AppCompatActivity() {
     
         internal lateinit var text: TextView
     
         override fun onCreate(savedInstanceState: Bundle?) {
             super.onCreate(savedInstanceState)
             setContentView(R.layout.activity_internal)
     
             text = internal_text
         }
     }
    
  4. Compile the project with gradle OR launch from Android studio

     ./gradlew assembleAlphaInternalDebug
    
  5. Notice that that build fails everytime:

     Parallel execution with configuration on demand is an incubating feature.
     e: /Users/kyle/Development/SyntheticExample/app/src/internal/java/com/leneau/syntheticexample/InternalActivity.kt: (6, 34): Unresolved reference: internal
     e: /Users/kyle/Development/SyntheticExample/app/src/internal/java/com/leneau/syntheticexample/InternalActivity.kt: (16, 16): Unresolved reference: internal_text
     
     FAILURE: Build failed with an exception.
     
     * What went wrong:
     Execution failed for task ':app:compileAlphaInternalDebugKotlin'.
     Compilation error. See log for more details
    

Expected Results

  1. The project should be able to compile.
  2. Multiple levels of product flavors should be supported.
  3. Android studio should reflect the issue ahead of time.

kotlin-synthetic-multi-flavor-sample's People

Contributors

kyleleneau avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.