java 使用单独的 App 作为依赖项时,包不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26050097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:13:17  来源:igfitidea点击:

Package does not exist when using separate App as a dependency

javaandroidgradleandroid-studio

提问by User24231

I'm trying to compile an App utilising a separate App as a dependency but when I compile referencing modules from this library I see several "error:package does not exist" and "error:cannot find symbol class" messages from graddle. The following are my two build files.

我正在尝试使用单独的应用程序作为依赖项编译应用程序,但是当我编译来自该库的引用模块时,我看到来自 graddle 的几个“错误:包不存在”和“错误:找不到符号类”消息。以下是我的两个构建文件。

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 19
    }

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

    packagingOptions {
        exclude 'AndroidManifest.xml'
        exclude 'resources.arsc'
        exclude 'classes.dex'
    }
}

dependencies {
    repositories {
        mavenCentral()
    }
    compile 'com.android.support:support-v4:+'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile 'com.android.support:support-v4:+'
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
    compile 'se.emilsjolander:stickylistheaders:2.+'
    compile 'com.googlecode.libphonenumber:libphonenumber:+'
    compile files('libs/crashlytics.jar')
    compile files('libs/httpclient-4.2.3.jar')
    compile files('libs/libphonenumber-5.9.jar')
    compile files('libs/mobileservices-0.2.0-javadoc.jar')
    compile files('libs/mobileservices-0.2.0.jar')
    compile files('libs/stringtotime-1.0.4.jar')
    compile files('libs/urbanairship-lib-2.0.2.jar')
    compile 'com.github.chrisbanes.actionbarpulltorefresh:extra-abs:+'
    compile files('libs/FlurryAnalytics-4.0.0.jar')
    compile 'com.squareup.picasso:picasso:2.3.3'
    compile project(':wheel')
}

Dependency gradle:

依赖等级:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "kankan.wheel"
        minSdkVersion 5
        targetSdkVersion 7
    }

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

}

Can anyone help/experienced this before? Android Studio does not highlight any issues in the class and I can ctrl+click through to the packages referenced which seems to mean it is set up correctly...

任何人都可以帮助/经历过这个吗?Android Studio 没有突出显示课程中的任何问题,我可以按 ctrl+click 到引用的包,这似乎意味着它设置正确......

Thanks!

谢谢!

采纳答案by Doge

You cannot have two gradle scripts using the com.android.applicationplugin at the same time. Change the dependency project to apply the 'library' plugin.

您不能同时使用两个 gradle 脚本com.android.application。更改依赖项目以应用“库”插件。

If that doesn't do it, change the targetSdkVersion of your dependency to that of your core project.

如果没有这样做,请将依赖项的 targetSdkVersion 更改为核心项目的 targetSdkVersion。

回答by Vladimir Berezkin

The buildTypes section should not be in library build.gradle file.

buildTypes 部分不应位于库 build.gradle 文件中。

回答by Man Vs Code

If you are using a Android library module as a dependency (i.e. mylib), then make sure in your app.iml file that you see the following line toward the end of the file:

如果您使用 Android 库模块作为依赖项(即 mylib),请确保在您的 app.iml 文件中看到文件末尾的以下行:

    <orderEntry type="module" module-name="mylib" exported="" />

回答by Vijay Rajanna

I had a similar issue posted here

我在这里发布了一个类似的问题

But I got it resolved using @Doge's suggestion, I converted the dependency android project to library project.

但是我使用@Doge 的建议解决了它,我将依赖项 android 项目转换为库项目。

Thanks.

谢谢。

回答by Mandav Prakash

Try changing min and target sdk to 11 and 19 according in dependency gradle-default config.

尝试根据依赖项 gradle-default 配置将 min 和 target sdk 更改为 11 和 19。