将项目转换为模块

时间:2016-06-01 13:30:21

标签: android gradle android-gradle pdfnet

我试图将PDFNet库集成到我的Android应用程序中,如果您下载SDK,您可以看到有一个项目CompleteReader(PDFNetAndroid-6.7.0.42960 \ PDFNetAndroid \ samples \ PDFViewCtrlProjects \ CompleteReader) 我想在我的应用程序中将此项目用作模块,因此我更改了build.gradle" com.android.application"到" com.android.library"

这里是原始的build.gradle:

description = 'This is a more complete demo app that showcases PDFViewCtrl and the Tools library and its controls.'

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.trello:victor:0.1.4'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'com.trello.victor'


dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':PDFViewCtrlTools')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.tonicartos:superslim:0.4.13'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0.0"
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            jniLibs.srcDirs = ['libs']
            svg.srcDir 'src/main/svg'
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
        debug {
            // Set package name to <app package>.debug to be able to install both debug and release apk on the same device
            applicationIdSuffix ".debug"
        }
    }

    lintOptions {
        // If true, stop the gradle build if errors are found
        abortOnError false
        //ignore 'ValidFragment'
    }

    productFlavors {
        armv7a {
            ndk {
                abiFilters "armeabi-v7a"
            }
        }
        arm {
            ndk {
                abiFilters "armeabi"
            }
        }
        x86 {
            ndk {
                abiFilters "x86"
            }
        }
        armv8 {
            ndk {
                abiFilters "arm64-v8a"
            }
        }
        x86_64 {
            ndk {
                abiFilters "x86_64"
            }
        }
        fat {
            ndk {
                abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86", "x86_64"
            }
        }
    }
}
task copyLibsToSamples << {
    ['libs'
     ].each { dest ->
        copy {
            from ('../../../lib/full') {
                include '**/*.so'
            }
            into dest
        }
     }
}

task copyJarToSamples(type: Copy) {
    ['../../../lib/src/PDFViewCtrlTools/libs'
     ].each { dest ->
        copy {
            from ('../../../lib') {
                include 'PDFNet.jar'
            }
            into dest
        }
     }
}

task copyResources << {
    ['res/raw'].each { dest ->
        copy {
            from ('../../../resource') {
                include '*.plugin'
            }
            into dest
        }
    }
}

task setupSample(dependsOn: [copyLibsToSamples, copyJarToSamples, copyResources])

preBuild.dependsOn setupSample

这个原始文件编译没有问题,但随着库的更改它不会构建,所以我删除了以下我读到的地方可能是问题:

repositories {
    mavenCentral()
}

好的,通过这个更改,似乎构建可以继续,我得到的下一个错误是跟随两个无法解析的引用(这一切都适用于原始文件未被修改!!!):

compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.tonicartos:superslim:0.4.13'

我已经在这个文件中尝试了很多东西已经好几天没有运气了,我删除了所有不需要的部件,移动了jcenter和mavencentral,添加它们,删除它们等等。 这是我当前的build.gradle也不起作用:

description = 'This is a more complete demo app that showcases PDFViewCtrl and the Tools library and its controls.'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.trello:victor:0.1.4'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.trello.victor'

dependencies {
    repositories {
        mavenCentral()
        jcenter()
    }
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':PDFViewCtrlTools')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:design:23.4.0'
    compile project(':superslim-0.4.13')
    compile 'com.jakewharton:butterknife:7.0.1'
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
            jniLibs.srcDirs = ['libs']
            svg.srcDir 'src/main/svg'
        }
    }

    lintOptions {
        // If true, stop the gradle build if errors are found
        abortOnError false
        //ignore 'ValidFragment'
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.2'
}

无论我改变什么,模块都无法编译,我得到执行失败的任务CompleteReader:compileDebugJavaWithJavac并且R没有被生成所以我得到了很多&#34;需要的常量表达式&# 34 ;.我再说一遍,在改变&#34; application&#34;到&#34;图书馆&#34;一切正常,我可以在手机上安装项目等。

你有什么想法有什么不对吗?我已经工作了3天没有运气!

1 个答案:

答案 0 :(得分:1)

看起来这个问题与奶油刀有关。 在PDFNet Android SDK的未来版本中,我们将在任何示例项目中删除butterknife的使用,以方便用户使用。

与此同时,我们建议您在CompleteReader示例项目中删除butterknife的使用。为此:

  • 按照自述文件
  • 中的说明打开CompleteReader示例项目
  • 从CompleteReader&#39; ls文件
  • 中删除compile 'com.jakewharton:butterknife:7.0.1'
  • 在尝试编译源代码时处理所有错误,即在build.gradleBaseFileAdapter.java类更改为以下内容:

    ContentViewHolder
  • 对使用butterknife

  • 的所有其他UI组件执行上述操作
  • 在项目编译完成后将应用程序转换为库