Ionic 2-无法使用AAR文件/ iOS框架添加自定义android / ios插件

时间:2018-10-23 14:40:01

标签: android ios ionic-framework ionic2 cordova-plugins

我有一个框架。我在git上创建了存储库以将其安装为我的项目的插件。它在没有aar框架的情况下进行了测试。但是添加aar框架后,我面临着values.xml的aar框架问题。借助插件,我可以在项目内部安装aar框架。以下是我的项目文件。请让我知道我在做什么错。

1。 plugin.xml

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-testpayment" version="1.0.0">
   <name>TestPayment</name>
   <js-module name="TestPayment" src="www/TestPayment.js">
      <clobbers target="TestPayment" />
   </js-module>
   <platform name="android">
      <config-file parent="/*" target="res/xml/config.xml">
         <feature name="TestPayment">
            <param name="android-package" value="cordova.plugin.testpayment.TestPayment" />
         </feature>
      </config-file>
      <config-file parent="/*" target="AndroidManifest.xml" />
      <source-file src="src/android/TestPayment.java" target-dir="src/cordova/plugin/testpayment/TestPayment" />
      <framework src="src/android/liquidsdk.gradle" custom="true" type="gradleReference" />
      <resource-file src="src/android/libs/widget-debug.aar" target="libs/widget-debug.aar" />
      <resource-file src="src/android/res/values/colors.xml" target="res/values/colors.xml" />
      <resource-file src="src/android/res/values/strings.xml" target="res/values/strings.xml" />
      <resource-file src="src/android/res/values/styles.xml" target="res/values/styles.xml" />
   </platform>
   <platform name="ios">
      <config-file parent="/*" target="config.xml">
         <feature name="TestPayment">
            <param name="ios-package" value="TestPayment" />
         </feature>
      </config-file>
      <framework src="src/ios/LiquidPayWidget.framework" custom="true" embed="true" />
      <source-file src="src/ios/TestPayment.m" />
   </platform>
</plugin>

2。项目结构-

| src-
    | android
           | libs
               | XYZ.aar
           | res
               | values
                     | colors.xml
                     | strings.xml
                     | styles.xml
           | myFile.gradle
           | myFile.java
    | ios
           | XYZ.framework
           | myFile.m
| www
    | myPlugin.js
| build-extras.gradle
| package.json
| plugin.xml

3。在AAR文件的values.xml中获取错误

Information:Gradle tasks [:app:assembleDebug]
/Users/mobilesolution/.gradle/caches/transforms-1/files-1.1/widget-debug.aar/bcf9996b5e370c6ae472fa0793a77af4/res/values/values.xml
Error:(57, 5) error: style attribute 'attr/colorPrimary (aka io.ionic.starter:attr/colorPrimary)' not found.
Error:(57, 5) error: style attribute 'attr/colorPrimaryDark (aka io.ionic.starter:attr/colorPrimaryDark)' not found.
Error:(57, 5) error: style attribute 'attr/colorAccent (aka io.ionic.starter:attr/colorAccent)' not found.
Error:(62, 5) error: style attribute 'attr/windowActionBar (aka io.ionic.starter:attr/windowActionBar)' not found.
Error:(62, 5) error: style attribute 'attr/windowNoTitle (aka io.ionic.starter:attr/windowNoTitle)' not found.
Error:resource style/Theme.AppCompat.Light.DarkActionBar (aka io.ionic.starter:style/Theme.AppCompat.Light.DarkActionBar) not found.
Error:resource style/ThemeOverlay.AppCompat.Dark.ActionBar (aka io.ionic.starter:style/ThemeOverlay.AppCompat.Dark.ActionBar) not found.
/Users/mobilesolution/Documents/Vishal Gole/LiquidPay/IonicApp/PayApp/platforms/android/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values/values.xml
Error:(69) style attribute 'attr/colorPrimary (aka io.ionic.starter:attr/colorPrimary)' not found.
Error:(70) style attribute 'attr/colorPrimaryDark (aka io.ionic.starter:attr/colorPrimaryDark)' not found.
Error:(71) style attribute 'attr/colorAccent (aka io.ionic.starter:attr/colorAccent)' not found.
Error:(75) style attribute 'attr/windowActionBar (aka io.ionic.starter:attr/windowActionBar)' not found.
Error:(76) style attribute 'attr/windowNoTitle (aka io.ionic.starter:attr/windowNoTitle)' not found.
Error:resource style/ThemeOverlay.AppCompat.Light (aka io.ionic.starter:style/ThemeOverlay.AppCompat.Light) not found.
Error:failed linking references.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 5s
Information:18 errors
Information:0 warnings
Information:See complete output in console

-如果我做错了什么,请允许我。

1 个答案:

答案 0 :(得分:1)

**ADDING AAR/FRAMEWORK IN IONIC 2 PROJECT**

1)首先,您不能将AAR /框架直接添加到离子项目中。

2)您需要创建cordova插件才能实现此目的

创建插件

1)请按照以下步骤

npm install -g plugman

2)然后

plugman create --name (PLUGIN NAME) --plugin_id cordova-plugin-(PLUGIN NAME) --plugin_version 1.0.0

3)到

的路径
cd (PLUGIN NAME)

plugman platform add --platform_name ios

plugman platform add --platform_name android

4)创建包.json文件

 plugman createpackagejson .

5)全局cordova插件结构:

 pluginFolder/

  build-extras.gradle

  plugin.xml

  myaarfolder/

src/

android/

  mybuild.gradle

  (PLUGIN NAME).java

6)在plugin.xml文件中:

   <framework src="src/android/mybuild.gradle" custom="true" type="gradleReference"/>

<resource-file src="myaarfolder/my.aar" target="libs/my.aar" />

7)在mybuild.gradle

repositories{    

  jcenter()

  flatDir {

     dirs 'libs'

  }

}

dependencies {

  compile(name:'my', ext:'aar')

 }

android {

   packagingOptions {

      exclude 'META-INF/NOTICE'

      exclude 'META-INF/LICENSE'

     }

  }

8)现在将插件添加到您创建的离子项目中

ionic cordova plugin add (PLUGIN_PATH)

完成上述步骤后,我执行了项目,但是/// CORDOV / EXEC不可用 \

我在ios框架中尝试过,我也遇到了相同的错误