2015-09-02 32 views
3

我终于将我的eclipse android项目迁移到Android Studio。我创建了一个包含两个模块的项目。一个模块是一个图书馆项目。另一个是简单的活动项目,其中包括图书馆模块。Android Studio库项目引用未解决的符号

Project/ 
    app/  (Activity Project) 
    br_lib/ (Library Project) 

在应用程序的“模块设置”中,我将一个dependency添加到lib模块中。 的LIB模块项目通常会生成,但我的应用程序模块构建失败每次我让到lib模块类的一个参考:

import org.apache.http.client.HttpClient; 
import org.cddevlib.breathe.setup.Utils <-- // lib refrence; 


public class MainActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Utils.convertName(""); // <--- lib module static class; 
    } 
} 

错误:

Error:(9, 34) error: cannot find symbol class Utils 
Error:(25, 9) error: cannot find symbol variable Utils 

有什么不对?我错过了什么?谢谢

这是应用模块gradle这个:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.0" 

defaultConfig { 
    applicationId "pro.breathe.cddev.org.br_gold" 
    minSdkVersion 22 
    targetSdkVersion 22 
    versionCode 1 
    versionName "1.0" 
} 
buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile project(':br_lib') 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
} 

这是LIB模块gradle这个:

apply plugin: 'com.android.library' 
android { 
compileSdkVersion 22 
buildToolsVersion "23.0.0" 

defaultConfig { 
    minSdkVersion 9 
    targetSdkVersion 9 
} 

dependencies { 
    compile 'com.android.support:support-v4:22.2.1' 
    compile 'com.android.support:design:22.2.1' 
    compile 'com.android.support:appcompat-v7:22.2.1' 
    compile 'com.android.support:cardview-v7:22.2.1' 
    compile 'com.android.support:gridlayout-v7:22.2.1' 
    compile 'com.android.support:recyclerview-v7:22.2.1' 
    compile 'com.google.android.gms:play-services:7.8.0' 
} 

buildTypes { 
    release { 
     minifyEnabled true 
     proguardFiles 'proguard.cfg' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
} 

这是项目的摇篮:

buildscript { 
    repositories { 
    jcenter() 
    } 
dependencies { 
    classpath 'com.android.tools.build:gradle:1.3.0' 

    // NOTE: Do not place your application dependencies here; they belong 
    // in the individual module build.gradle files 
} 
} 

allprojects { 
repositories { 
    jcenter() 
} 
} 

设置gradle这个是:

include ':app', ':br_lib' 
+0

编译文件位置不正确 –

+1

发布您的settings.gradle并且不要使用您的jar文件的绝对路径。 此外,您正在使用不同版本的支持库。 –

+0

是的,我认为这是您的位置错误。我是对的先生加布里埃尔 –

回答

0

编译文件位置不正确。这就是警告抛出的原因。您永远不会找到您的驱动器名称。将其设置到您的项目lib文件夹中。您需要检查How to add library in Android Studio

+1

我更新了我的编译文件位置,但在访问我的应用程序模块中的lib模块类时仍然出错 –

+0

我没有请参阅您在本地设置库的更新依赖关系 –

+0

无法找到符号表示您没有正确调用您的库或缺少 –

1

今天在5个模块(其中2个模块为com.android.library模块)的项目中出现同样的问题。在对我的build.gradle文件进行了大量试验和错误更改之后,解决方案最终涉及在库模块的gradle文件中包含publishNonDefault true属性。

我发现这个职位是非常有帮助的: StackOverflow - Product Flavors and Library Publication

我的应用gradle这个文件最终看上去像(代码故意省略):

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion '25.0.2' 

    packagingOptions { 
     exclude 'LICENSE.txt' 
     exclude 'NOTICE' 
     exclude 'META-INF/LICENSE' 
    } 

    defaultConfig { 
    } 

    productFlavors { 
     funapp { 
      applicationId "com.funapp.package" 
     } 
     funappbeta { 
      applicationId "com.funapp.beta" 
     } 
    } 

    signingConfigs { 
     googleplay { 
     } 
    } 

    buildTypes { 
     debug { 
      minifyEnabled false 
      debuggable true 
      signingConfig signingConfigs.debug 
     } 
     release { 
      debuggable false 
      signingConfig signingConfigs.googleplay 
     } 
    } 
} 

configurations { 
    funappDebugCompile 
    funappReleaseCompile 
    funappbetaDebugCompile 
    funappbetaReleaseCompile 

    // Establish debug compile dependencies for build variants 
    [funappDebugCompile, funappbetaDebugCompile].each { 
     it.extendsFrom commonFunSdkDebugCompile 
    } 
    // Establish release compile dependencies for build variants 
    [funappReleaseCompile, funappbetaReleaseCompile].each { 
     it.extendsFrom commonFunSdkReleaseCompile 
    } 
    // Common Android and JUnit testing dependencies (JUnit tests can be run 
    // using only a JVM; Android tests require a device or emulator) 
    [androidTestCompile, testCompile].each { 
     it.extendsFrom commonTestCompile 
    } 
} 

dependencies { 
    commonFunSdkDebugCompile project (path: ':fun-sdk', configuration: 'debug') 
    commonFunSdkReleaseCompile project (path: ':fun-sdk', configuration: 'release') 

我的图书馆gradle这个文件看起来像:

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 25 
    buildToolsVersion '25.0.2' 

    publishNonDefault true // <-- This happened to be the key component 
    packagingOptions { 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
    } 

    defaultConfig { 
    } 

    buildTypes { 
     debug { 
     } 
     release { 
     } 
    } 
} 

configurations { 
    debug 
    release 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
相关问题