2017-08-14 104 views
0

我有几个com.android.application模块(即导入他们自己的库等),但不是将所有源代码转储到一个模块中,而是想要一个调用它们的模块。集成多个Android应用程序

但是,当我想从新的集成模块调用Activity时,Android Studio无法找到活动类。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.selector_activity); 
    getSupportActionBar().hide(); 

    Button button1= (Button) findViewById(R.id.selector_Button1); 
    button1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent intent = new Intent(getApplicationContext(), com.myCompany.referenceApp.activity.SplashActivity.class); 
      startActivity(intent); 
     } 
    }); 
} 

这是一个集成模块的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.2" 

    defaultConfig { 
     applicationId "com.mycompany.integratedgui" 
     minSdkVersion 21 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 

     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile 'com.android.support:appcompat-v7:25.3.1' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    testCompile 'junit:junit:4.12' 
    compile project(path: ':referenceapp') 
} 

的Android Studio将总是失败的编制,并提示“Alt键进入”以包括模块“referenceapp”的依赖,并不断增加已经在构建文件中的语句compile project(path: ':referenceapp')

我必须做些什么才能将许多不同的应用程序包含到这个集成的应用程序中,这些应用程序将单独调用它们?

回答

0

导入Android Studio中的多个项目。 在settings.gradle文件,添加所有模块像这样的例子:

include ':nxpnfcandroidlib' 
include ':sampleNxpNfcLib' 
include ':AndrSdkTestBench' 
project(":sampleNxpNfcLib").projectDir = file("../../02_Samples/sampleNxpNfcLib") 
project(":AndrSdkTestBench").projectDir = file("../../04_Test/AndrSdkTestBench/app") 

如果任何模块中需要添加的依赖,那么你可以添加以下代码,例如:

compile project(':nxpnfcandroidlib')的生成。 gradle文件