2016-09-29 7 views
0

私はJavaソースコード、リソース(マニフェスト、レイアウト)ファイルを含む私自身のプロジェクトのライブラリを作成したいと私はAndroidスタジオ2.1.2。どのように私はそれを作成することができますし、いずれかを提案してください - 1).AARではない.jarライブラリを作成したいです。
2)別のライブラリや依存関係を追加するにはどうすればいいですか?アンドロイドスタジオを使用して別のプロジェクトを使用するために私のアンドロイドプロジェクトのライブラリを作成する2.1.2

ありがとうございます。

+0

であるあなたが投稿する前にSO上samethingを検索しました質問 ? – SilentKiller

+0

はい、私は.aarファイルを作成する方法しかありません。 –

答えて

0

は、あなたは自分のアプリのbuild.gradleファイル

サーチライン

apply plugin: 'com.android.application' 

に変更し、

apply plugin: 'com.android.library' 

、最も重要なことはこの行を削除するには、それを変更する必要が

applicationId "your_package_name" 

f defaultConfigブロックを開きます。ライブラリにはアプリケーションIDがないためです。あなたのプロジェクトをビルドすると、フォルダの中に 'aar'フォルダがあります。

projectfolder - >ビルド - >出力 - > AAR - >

LIBRARY_FILE編集:

とJarファイルについては、以下のコマンドを使用して

を通過してくださいRun gradlew makeJar command from your project root.

+0

それは間違った仲間です!彼は瓶のライブラリが欲しかった! –

+0

しかし、私はどのようにカスタマイズしますか.aarファイル私はリソースフォルダを表示する場合は、ユーザーに可能ですか? –

+0

@Rajan編集を確認してください。 – SilentKiller

0
+0

1)** http://stackoverflow.com/questions/21712714/how-to-make-a-jar-out-from-an-android-studio-project**ソースコードのみを作成します。リソース?? –

+0

2)** http://www.technetexperts.com/mobile/export-jar-file-from-android-studio-project/**はjarを作成しますが、この.jarファイルを別のプロジェクトに追加するとエラーになります設定ファイルがありません –

+0

あなたの質問にエラーメッセージを投稿できますか? –

0

build.gradleファイル

build.gradle file apply plugin: 'com.android.library' 
buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:2.1.2' 

     classpath 'com.google.gms:google-services:3.0.0' 
    } 
} 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.3" 

    publishNonDefault true 

    defaultConfig { 
     minSdkVersion 11 
     targetSdkVersion 23 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    sourceSets { 
     main { 
      //Path to your source code 
      java { 
       srcDir 'src/main/java' 
      } 
      resources { 
       srcDir 'src/../lib' 
      } 
     } 
    } 

    // This is important, it will run lint checks but won't abort build 
    lintOptions { 
     abortOnError false 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 
    compile 'com.android.support:appcompat-v7:23.4.0' 
    compile files('libs/AdvancedWebView.jar') 
    compile project(':ShortcutBadger') 
    compile files('libs/commons-net-3.4.jar') 
    compile files('libs/ksoap2-android-assembly-3.6.0-jar-with-dependencies.jar') 
} 

task clearJar(type: Delete) { 
    delete 'release/' + POM_ARTIFACT_ID + '_' + VERSION_NAME + '.jar' 
} 

task makeJar(type: Copy) { 
    from('build/intermediates/bundles/debug/') 
    into('release/') 
    include('classes.jar') 
    rename ('classes.jar', POM_ARTIFACT_ID + '_' + VERSION_NAME + '.jar') 
} 

makeJar.dependsOn(clearJar, build) 

...これらのチュートリアルを参照してください、これは私のmainifestファイル

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="package name"> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.CAMERA" /> 
    <uses-feature android:name="android.hardware.camera" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 

    <application 
     android:allowBackup="true" 
     android:label="@string/app_name" 
     android:supportsRtl="true"> 

     <activity android:name=".SplashScreen" 
      android:label="@string/app_name"/> 

     <activity 
      android:name=".MainActivity"     
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" 
      android:label="@string/app_name" > 
     </activity> 

     <activity android:name=".NextActivity" 
      android:label="@string/app_name"/> 

    </application> 

</manifest> 
関連する問題