【问题标题】:Using jar file with phonegap/cordova plugin使用带有 phonegap/cordova 插件的 jar 文件
【发布时间】:2015-09-17 18:32:41
【问题描述】:

我正在为cordova v5.0.0 做一个插件 该插件适用于 gradle 依赖项,但我需要使用 jar 文件

所以我将文件添加到 plugin.xml 的源代码部分

<platform name="android">
    <config-file target="res/xml/config.xml" parent="/*">
        <feature name="SygicPlugin">
            <param name="android-package" value="com.test.plugi"/>
        </feature>
    </config-file>
    <source-file src="src/android/libs/MyJar.jar" target-dir="src/libs/" />        
    <source-file src="src/android/MyPlugin.java" target-dir="src/" />
    <framework src="src/android/build.gradle" custom="true" type="gradleReference" />
 </platform>          

这是我的 build.gradle 文件

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:22.2.0'
}

但 android 构建过程失败:

MyPlugin.java:4:错误:com.test.jars.model 包不存在 导入 com.jar.jarType;

我找到了很多使用 ant 进行构建的“示例”,但我正在使用 gradle,我想继续使用它。

您知道如何使用插件中的 jar 并正确配置 gradle 以进行构建吗?

提前致谢。

W

【问题讨论】:

    标签: android cordova maven gradle phonegap-plugins


    【解决方案1】:

    主要问题是它没有找到 jar 文件,但它默默地失败了。 当我将文件更改为:

    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    dependencies {
        compile name: 'MyJar'
    }
    

    我可以看到错误。路径库不存在。 所以我需要在我的 jar 中使用我的 plugin.xml 文件 src/lib 中使用的相同路径。太明显了……我觉得自己像个菜鸟:)

    我最终的 build.gradle 文件是:

    dependencies {
      compile fileTree(dir: 'src/libs', include: ['*.jar'])
      compile 'com.android.support:appcompat-v7:22.2.0'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2013-01-10
      • 1970-01-01
      相关资源
      最近更新 更多