Gradle编译:未找到软件包

时间:2019-02-14 23:08:03

标签: java maven gradle

出于调试OTGViewer的目的,我试图将一个项目(IGLogger)包含到另一个项目(OTGViewer)中。因此,我重写了IGLogger,以便将函数的调用(Log.d等)转储到文件中,现在我正尝试将其包括在OTGViewer中:

//import android.util.Log;
import com.iglogger.iglogger;

在执行“ gradle build --debug”时,我却遇到了

[root@v48807 OTGViewer]# cat err.log
5889:23:46:03.189 [ERROR] [system.err] /var/projects/.otg/OTGViewer/mobile/src/main/java/com/androidinspain/otgviewer/MainActivity.java:18: error: package com.iglogger does not exist
5890:23:46:03.195 [ERROR] [system.err] import com.iglogger.iglogger;
5891:23:46:03.195 [ERROR] [system.err]                    ^
5901:23:46:09.426 [ERROR] [system.err] /var/projects/.otg/OTGViewer/mobile/src/main/java/com/androidinspain/otgviewer/MainActivity.java:72: error: cannot find symbol
5902:23:46:09.426 [ERROR] [system.err]             Log.d(TAG, "onCreate");
5903:23:46:09.434 [ERROR] [system.err]             ^
5904:23:46:09.440 [ERROR] [system.err]   symbol:   variable Log
5905:23:46:09.441 [ERROR] [system.err]   location: class MainActivity
5906:23:46:09.644 [ERROR] [system.err] /var/projects/.otg/OTGViewer/mobile/src/main/java/com/androidinspain/otgviewer/MainActivity.java:111: error: cannot find symbol
5907:23:46:09.659 [ERROR] [system.err]                 Log.d(TAG, "No transition needed. Already in that fragment!");
5917:23:46:09.666 [ERROR] [system.err]                 ^
5918:23:46:09.666 [ERROR] [system.err]   symbol:   variable Log

但是我实际上是使用iglogger创建jar并将其安装在本地Maven存储库中的:

[root@v48807 IGLogger]# cat compile.sh
#!/usr/bin/env bash
set -e
set -o errexit

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
cd $DIR

#javac -bootclasspath /opt/android-sdk/platforms/android-26/android.jar iglogger.java
#javac -sourcepath /opt/android-sdk/platforms/android-26/android.jar iglogger.java
javac -source 1.8 -target 1.8 com/iglogger/iglogger.java

dx --dex --output=iglogger.dex com/iglogger/iglogger.class
#baksmali iglogger.dex
#java -jar /var/projects/.otg/smali/baksmali/build/libs/baksmali.jar disassemble iglogger.dex

apktool.sh b . -o iglogger.apk
apktool.sh d iglogger.apk -f -o iglogger-unpacked
rm -rf iglogger.apk
mv iglogger-unpacked/smali_iglogger/com/iglogger/iglogger.smali .
rm -rf iglogger-unpacked/

cd com/iglogger
jar cf iglogger.jar iglogger.class

(我还在上面制作了一个smali文件,但想法是创建一个jar文件并将代码作为软件包安装在存储库中-见下文)

[root@v48807 IGLogger]# cat mvn-install.sh
#!/usr/bin/env bash
mvn install:install-file -Dfile=com/iglogger/iglogger.jar -DgroupId=com.iglogger -DartifactId=iglogger -Dversion=0.0.1 -Dpackaging=jar

我还修改了OTGViewer的gradle文件,以声明存在依赖关系和新的存储库:

[root@v48807 OTGViewer]# cat build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

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

allprojects {
    repositories {
        jcenter()
        google()
        mavenLocal()
    }
}
[root@v48807 OTGViewer]# cat mobile/build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 26

    defaultConfig {
        applicationId "com.androidinspain.otgviewer"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions{
        abortOnError false
    }
    compileOptions   {
      sourceCompatibility = '1.8'
      targetCompatibility = '1.8'
    }
}

dependencies {
    compile 'com.github.mjdev:libaums:0.5.5'
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.android.support:design:26.0.1'
    compile 'com.android.support:recyclerview-v7:26.0.1'
    compile 'com.iglogger:iglogger:0.0.1'
}
[root@v48807 OTGViewer]#

那我想念什么?

编辑: 好的。我确保iglogger的jar位于javac的-classpath参数中,并且文件存在:

[root@v48807 OTGViewer]# gradle build --stacktrace --debug &> debug.log

[root@v48807 OTGViewer]# cat debug.log | grep classpath | grep -n iglogger > iglogger.log && vi iglogger.log

[root@v48807 OTGViewer]# ls /root/.m2/repository/com/iglogger/iglogger/0.0.1/iglogger-0.0.1.jar
-rw-r--r-- 1 root root 8319 Feb 17 21:10 /root/.m2/repository/com/iglogger/iglogger/0.0.1/iglogger-0.0.1.jar
[
[root@v48807 ~]#

因此,如果文件存在,那么可能是什么问题?为什么不将其视为包装?我是通过import指令正确导入的,对吧?

0 个答案:

没有答案