我正在尝试构建一个使用我也创建的
Android库的
Android应用程序.项目结构如下:
/mainProject |- /myLibrary |- build.gradle |- (Java Sources and files) |- /app |- build.gradle |- (Java Sources and files) |- settings.gradle |- build.gradle
mainProject / settings.gradle包含:
include ':app',':myLibrary'
mainProject / build.gradle包含:
// Top-level build file where you can add configuration options common to all sub-projects/modules. 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() } } task clean(type: Delete) { delete rootProject.buildDir }
mainProject / myLibrary / build.gradle如下所示:
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 } } apply plugin: 'com.android.library' android { compileSdkVersion 21 buildToolsversion "23.0.1" defaultConfig { minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { debug{ buildConfigField "String","LIBRARY_ENDPOINT","\"https://dev-library.company.com/\"" } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' buildConfigField "String","\"https://library.company.com/\"" } } } repositories { jcenter() } dependencies { compile filetree(dir: 'libs',include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.+' compile 'com.github.satyan:sugar:1.3' testCompile 'junit:junit:4.12' compile 'commons-io:commons-io:2.4' androidTestCompile 'junit:junit:4.12' }
mainProject / app / build.gradle文件包含:
apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsversion "23.0.1" defaultConfig { applicationId "com.company.app" minSdkVersion 14 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { debug { applicationIdSuffix ".debug" buildConfigField "String","APP_ENDPOINT","\"https://dev-app.company.com/\"" } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),"\"https://app.company.com/\"" } } packagingOptions { exclude 'meta-inf/LICENSE.txt' exclude 'meta-inf/NOTICE.txt' } } dependencies { compile filetree(include: ['*.jar'],dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:21.+' compile 'com.google.android.gms:play-services-location:8.1.0' compile 'commons-io:commons-io:2.4' compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar' compile 'com.github.clans:fab:1.6.1' compile 'joda-time:joda-time:2.8.2' compile 'com.android.support:recyclerview-v7:+' compile 'com.squareup.picasso:picasso:2.5.2' compile project(':myLibrary') }
我最初在IDE中遇到错误,但添加最终的编译项目行清除了这些错误,因此IDE根本不显示任何错误.但是,当我运行gradle构建时,我看到:
:app:compileDebugJavaWithJavac /AndroidStudioProjects/mainProject/app/src/main/java/com/company/app/MainActivity.java:17: error: cannot find symbol import com.company.mylibrary.LibraryClass; ^ symbol: class LibraryClass location: package com.company.mylibrary /AndroidStudioProjects/mainProject/app/src/main/java/com/company/app/MainActivity.java:29: error: cannot find symbol LibraryClass.setup("562e7d58628ee16894db98df",getApplicationContext()); ^ symbol: variable LibraryClass location: class MainActivity 2 errors Failed FAILURE: Build Failed with an exception. * What went wrong: Execution Failed for task ':app:compileDebugJavaWithJavac'. > Compilation Failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD Failed Total time: 8.143 secs
我很困惑,因为IDE没有显示任何错误,我相信我告诉gradle应用程序项目在编译时确实需要myLibrary项目.我在这里找到的答案似乎都没有同样的问题.
有谁看到我做错了什么?
解决方法
终于弄明白了这个问题.我的图书馆正在使用proguard,并且出于某种原因,这会让事情搞得一团糟.我从库项目中的build.gradle中删除了minify和proguard行,它工作正常.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。