Android Studio: Multi Module Project with different Google Play Service libraries


(Rene Herlein) #1

Hi specialists,

i build a project in Android Studio with this config:

  • App
  • Calc
  • Weather (Included as library module - using Goolge Play Service 6.1.71)
  • Maps (Included as library module - using Google Play Service 9.2.1)

The Weather library is an old one with a lot of code (for Google Play Service 6.1.71) and the Maps library is a new one (build with Google Play Service 9.2.1). When i install the APK the Application Weather crashed on avtivate (onclick Button).

Here is the logcat:

` _07-22 16:36:55.003 26256-26256/bakteriusdeveloper.master I/art: Rejecting re-init on previously-failed class java.lang.Class<com.cs.android.weminder.MainActivity>_
_    07-22 16:36:55.003 26256-26256/bakteriusdeveloper.master D/AndroidRuntime: Shutting down VM_
_    07-22 16:36:55.004 26256-26256/bakteriusdeveloper.master E/AndroidRuntime: FATAL EXCEPTION: main_
_                                                                           Process: bakteriusdeveloper.master, PID: 26256_
_                                                                           java.lang.IllegalStateException: Could not execute method for android:onClick_`

Here my manifest from the weather module:

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
useLibrary  'org.apache.http.legacy'
defaultConfig {
  //  applicationId "com.cs.android.weminder"
    minSdkVersion 19
    targetSdkVersion 21

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

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/acra-4.5.0.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:6.1.71'

}

Here the manifest from the map module:

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
  //  applicationId "fishingmaster.map"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"

    // Enabling multidex support.
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),      'proguard-rules.pro'
    }
}
}

dependencies {
compile 'com.android.support:multidex:1.0.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:9.2.1'
}

Here the manifest from the app:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "bakteriusdeveloper.master"
    minSdkVersion 19
    targetSdkVersion 21

    // Enabling multidex support.
    multiDexEnabled true

    versionCode 3
    versionName "1.2"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),     'proguard-rules.pro'
    }
}
}

dependencies {
compile project(':mapmarker')
compile project(':weather')
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.4.0'

}

This is my start activity (javafile) where i placed the calls for the another activities:

package bakteriusdeveloper.master;

import android.content.Context;
import android.content.Intent;
import android.support.multidex.MultiDex;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RelativeLayout;


public class StartActivity extends AppCompatActivity {


@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

public void gotocalc(View view)
{
    Intent intent = new Intent(StartActivity.this, MainActivity.class);
    startActivity(intent);
}

public void gotomap (View view)
{
 Intent intent = new Intent(this, fishingmaster.map.MapsActivity.class);
  startActivity(intent);
}

public void gotoweather(View view)
{
    Intent intent = new Intent(this, com.cs.android.weminder.MainActivity.class);
    startActivity(intent);
}
RelativeLayout leftRL;
// RelativeLayout rightRL;
DrawerLayout drawerLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_start);

    leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
 //   rightRL (RelativeLayout)findViewById(R.id.whatYouWantInRightDrawer);
    drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
}

public  void onLeft(View view) {
    drawerLayout.openDrawer(leftRL);
}

I think the problem is, that i use different versions from google play service. But i cant rewrite the weather application (there is to much code). The best way for me is to try run the configuration with the different versions of google play service.

I tried a lot since 3 days. I tried with exclude, i tried with uses-library, i tried with x, i tried with with y… I have read a lot about gradle but i was not able to find a way to fix this problem. My Pc is boiled through the whole gradle building :-/

Is there a way, to configure my different Versions of Play-Service? Like the Version 6.1.71 is only active for weather and the Version 9.2.1 is only active for Maps? I am sorry, i am not the crack for Gradle…

Is there anybody out there, who can help me?