error: package does not exist android google mobil

2019-09-02 21:06发布

问题:

There are a few similar questions on here but I am having trouble finding a solution.

I am using the google mobile backend starter https://cloud.google.com/cloud/samples/mbs/ and everything works until I want to try and send notifications from GCMintentService.java. If I call

Intent resultIntent = new Intent(this, MyActivity.class);

I get an error that MyActivity in the App module does not exist. I am pretty sure I should add something like

compile project(':app')

to the gradle dependances of the core module that holds GCMintentService.java but if I do I get an error saying that app is not a library?

Here is the core module gradle dependancies

dependencies {
    compile('com.google.cloud.backend:mobilebackend:v1-1.19.0-SNAPSHOT') {
        exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
    }
    compile 'com.android.support:appcompat-v7:20.+'
    compile 'com.google.api-client:google-api-client-android:1.19.0'
    compile 'com.google.http-client:google-http-client:1.19.0'
    compile('com.google.http-client:google-http-client-android:1.19.0') {
        exclude(group: 'com.google.android', module: 'android')
        exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
    }
    compile 'com.google.http-client:google-http-client-gson:1.19.0'
    compile 'com.google.http-client:google-http-client-jackson:1.19.0'
    compile 'com.google.http-client:google-http-client-jackson2:1.19.0'
    compile 'com.google.oauth-client:google-oauth-client:1.19.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.fasterxml.jackson.core:jackson-core:2.1.3'
    compile 'org.codehaus.jackson:jackson-core-asl:1.9.13'
    compile 'com.google.code.findbugs:jsr305:1.3.9'
    compile 'com.mcxiaoke.volley:library:1.0.+@aar'
    compile 'com.google.android.gms:play-services:4.4.52'
}

回答1:

If your app project isn't a library (if it uses apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library'), then other modules can't depend on it. You can only depend on libraries, not application modules.

You may need to take your common code that everything depends on and break it out into a separate module that both your core module and your app module can depend on.