title: How to access the class of product flavor from main directory?
body: <p>There are two product flavor in my application i-e<br>
  <strong>flavorOne(src/flavorOne/java)</strong> and <strong>flavorTwo(src/flavorTwo/java)</strong>. <strong>Main (src/main/java)</strong> is directory form where both flavor are using the classes. I want to start activity <strong>src/flavorTwo/java/ActivityB</strong>.java  from the Activity present in <strong>src/main/java/ActivityA</strong>. while running the flavorTwo it works but when i switch the flavorOne it shows the import com.packagename.ActivityB error.</p>
  
  <pre><code>+ App // module
      |- src
         |- main// shared srcDir
            |- java
             |- SharedActivity
         + flavorOne
            |- java
             |- FlavorOneActivity
         + flavorTwo
            |- java
             |- FlavorTwoActivity
  </code></pre>
  
  <p>Here is SharedActivity.java in dir src/main/java/SharedActivity.java</p>
  
  <pre><code>package com.example.buildvariants;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  /**********************  works if it is in flavorOne otherwise it shows error on this package import ***********/
  import com.example.buildvariants.flavorOne.LoginActivity;
  
  public class SharedActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  
          //if flavor is flavorTwo hide the fab
          //else flavor is flavorOne show fab and launch activity under flavorOne/java/LoginActivity.java
          if (BuildConfig.FLAVOR.equalsIgnoreCase("flavorTwo")) {
              fab.setVisibility(View.GONE);
          } else {
              fab.setVisibility(View.VISIBLE);
              fab.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                              .setAction("Action", null).show();
                      startActivity(new Intent(SharedActivity.this, LoginActivity.class));
  
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>Activity  under <strong>flavorOne</strong> src/flavorOne/FlavorOneMainActivity.java</p>
  
  <pre><code>package com.example.buildvariants.flavorOne;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  
  import com.example.buildvariants.R;
  import com.example.buildvariants.SharedActivity;
  
  public class FlavorOneMainActivity extends AppCompatActivity {
  
      private static final String TAG =FlavorOneMainActivity.class.getSimpleName() ;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.flavor_one_activity_main);
          Intent intent = new Intent(FlavorOneMainActivity.this, SharedActivity.class);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>Activity  under <strong>flavorTwo</strong> src/flavorOne/FlavorTwoMainActivity.java</p>
  
  <pre><code>package com.example.buildvariants.flavorTwo;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v7.app.AppCompatActivity;
  
  import com.example.buildvariants.R;
  import com.example.buildvariants.SharedActivity;
  
  public class FlavorTwoMainActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.flavor_two_activity_main);
          startActivity(new Intent(FlavorTwoMainActivity.this, SharedActivity.class));
      }
  }
  </code></pre>
  
  <p>Shows <strong>error</strong> on package import of <strong>SharedActivity(src/main/java/)</strong> as listed below when i changed the build variants flavorTwo.</p>
  
  <pre><code>package com.example.buildvariants;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.design.widget.FloatingActionButton;
  import android.support.design.widget.Snackbar;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  /********error  on package import***********/
  import com.example.buildvariants.flavorOne.LoginActivity;
  
  public class SharedActivity extends AppCompatActivity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  
          //if flavor is flavorTwo hide the fab
          //else flavor is flavorOne show fab and launch activity under flavorOne/java/LoginActivity.java
          if (BuildConfig.FLAVOR.equalsIgnoreCase("flavorTwo")) {
              fab.setVisibility(View.GONE);
          } else {
              fab.setVisibility(View.VISIBLE);
              fab.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                              .setAction("Action", null).show();
                      startActivity(new Intent(SharedActivity.this, LoginActivity.class));
  
                  }
              });
          }
      }
  }
  </code></pre>
  
  <p>What would be the best solution for this problem?</p>