Gradle compilation: package not found

2020-04-18 08:53发布

问题:

I am trying to include one project (IGLogger) into another (OTGViewer) for the purpose of debugging OTGViewer. So I rewrote IGLogger so it dumps the callings of the functions (Log.d etc) to a file and right now I am trying to include it into the OTGViewer:

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

Yet while doing "gradle build --debug" I am having:

[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

Yet I actually created jar out of iglogger and installed it in the local Maven repository:

[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

(I also produced a smali file up above, but the idea is to create a jar file and install the code as a package in the repository -- see below)

[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

Also I modified the gradle files of OTGViewer to state that there is a dependency and a new repo:

[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]#

So what am I missing?

Edit: Alright. I made sure that iglogger's jar is in the -classpath parameter of javac and the file exist:

[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 ~]#

So if the file exist, then what might be wrong? Why it isn't recognized as a package? I am importing it correctly, through the import directive, right?