0

我知道这个问题以前问过,但任何答案帮助我。如何在Android中使用第三方jar文件

我想使用SVG,但Android无法看到SVG jar。我添加了构建路径。我将库结果作为libs文件夹。并且还在Android Manifest中添加了标签。但它没有奏效。

问候

这是我的Android清单:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.svgexample2" 
    android:versionCode="1" 
    android:versionName="1.0" > 

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="17" /> 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 

     <activity 
      android:name="com.example.svgexample2.MainActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter>   
     </activity> 
     <uses-library android:name="svg-android" android:required="true" /> 
    </application> 

</manifest> 

我的主要活动:

package com.example.svgexample2; 

import com.larvalabs.svgandroid.SVG; 
import com.larvalabs.svgandroid.SVGParser; 

import android.os.Bundle; 
import android.app.Activity; 
import android.graphics.Color; 
import android.view.Menu; 
import android.widget.ImageView; 
import android.widget.RelativeLayout; 

public class MainActivity extends Activity { 

     RelativeLayout mainLayout; 
     RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.MATCH_PARENT, 
       RelativeLayout.LayoutParams.WRAP_CONTENT); 
     ImageView myImg; 
     SVG svgFile; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

      mainLayout = new RelativeLayout(this); 
      myImg = new ImageView(this); 

      myImg.setBackgroundColor(Color.WHITE); 

      SVG svgFile = SVGParser.getSVGFromResource(getResources(), R.drawable.image); 
      myImg.setImageDrawable(svgFile.createPictureDrawable()); 

      mainLayout.addView(myImg); 
      setContentView(mainLayout); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

} 

这里是我的另外svgandroid.xml文件:

<?xml version="1.0" encoding="utf-8"> 
<permissions> 
<libraryname="svg-android" file="/home/breed/dev/Android/androidWorkspace/SvgExample2/libs/"/> 
</permissions> 

回答

0

AFAIK有不需要你在你的Manifest中放置一个uses-librarysvgandroid.xml也应该没用。只需将.jar文件放置在Android Eclipse项目的libs文件夹中即可。

+0

格林,我试过了。我得到“这个元素既没有附加源代码也没有附加Javadoc,因此没有找到Javadoc。”错误。 –

+0

Javadoc在这里没有关系。当您尝试构建或启动应用程序时,您看到哪条错误消息? – h22

+0

@BreedHansen什么不起作用?您的javadoc(鼠标悬停弹出窗口)显示“此元素既不......”或您的图像没有显示? – IronBlossom

相关问题