有两个项目:My project
和Library project
。
我已在Android工作室中导出Android library project to jar file successfully, built from aar
to jar
。
现在,我将jar
放入my project
以允许将其用作库。
清洁后&同步gradle成功。 My project
可以理解jar
库中的类是否正确。
但是在发布之后,它仍然会崩溃并且低于与jar library
相关的异常,
我不知道为什么,
知道的人,请告诉我如何解决,
谢谢,
p / s:实际上,我尝试将jar库发布到maven,所以我需要在发布之前进行测试。
如果我没有声明活动CustomCamera
和CustomGallery
,我将崩溃并获取异常,而不是在manifest.xml中声明活动。
异常
Process: mirrortowers.beautiful_bag.android.custom_camera.custom_gallery, java.lang.NoClassDefFoundError: Failed resolution of: Lmirrortowers/custom_camera_gallery_library/R$layout;
E/AndroidRuntime: at ui.activity.custom.camera.CustomCamera.onCreate(CustomCamera.java:93)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5975)
E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:147)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5253)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "mirrortowers.custom_camera_gallery_library.R$layout" on path: DexPathList[[zip file "/data/app/mirrortowers.beautiful_bag.android.custom_camera.custom_gallery-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
E/AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
E/AndroidRuntime: at ui.activity.custom.camera.CustomCamera.onCreate(CustomCamera.java:93)
E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5975)
E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2376)
E/AndroidRuntime: at android.app.ActivityThread.access$800(ActivityThread.java:147)
E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1281)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5253)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
E/AndroidRuntime: Suppressed: java.lang.ClassNotFoundException: mirrortowers.custom_camera_gallery_library.R$layout
E/AndroidRuntime: at java.lang.Class.classForName(Native Method)
E/AndroidRuntime: at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
E/AndroidRuntime: at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
E/AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
E/AndroidRuntime: ... 15 more
E/AndroidRuntime: Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
项目结构
尝试放入libs
文件夹并将其添加为库 - >不行。
尝试放入app
文件夹并将其添加为库 - >不行。
Jar库中的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mirrortowers.custom_camera_gallery_library">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:label="@string/app_name">
<!-- custom camera and gallery-->
<activity
android:name="ui.activity.custom.camera.CustomCamera"
android:screenOrientation="portrait"
/>
<activity android:name="ui.activity.custom.gallery.CustomGallery" />
</application>
</manifest>
项目中的Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mirrortowers.beautiful_bag.android.custom_camera.custom_gallery">
<!--<uses-permission android:name="android.permission.READ_PHONE_STATE" />-->
<uses-permission android:name="android.permission.CAMERA" />
<!--<uses-permission android:name="android.permission.INTERNET" />-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<!-- Activity -->
<activity
android:name=".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>
<activity
android:name=".DonateActivity"
android:theme="@style/AppDialogTheme" />
<!-- custom camera and gallery-->
<activity
android:name="ui.activity.custom.camera.CustomCamera"
android:screenOrientation="portrait" />
<activity android:name="ui.activity.custom.gallery.CustomGallery" />
</application>
jar库中的app.build.gradle
apply plugin: 'com.android.library'
apply plugin: 'maven'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.10'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.google.android.gms:play-services:8.1.0'
}
// ext is a gradle closure allowing the declaration of global properties
ext {
PUBLISH_GROUP_ID = 'android.mirrortowers'
PUBLISH_ARTIFACT_ID = 'custom_camera_gallery'
PUBLISH_VERSION = '1.0.0'
}
def groupId = project.PUBLISH_GROUP_ID
def artifactId = project.PUBLISH_ARTIFACT_ID
def version = project.PUBLISH_VERSION
def localReleaseDest = "${buildDir}/release/${version}"
uploadArchives {
repositories.mavenDeployer {
pom.groupId = groupId
pom.artifactId = artifactId
pom.version = version
// Add other pom properties here if you want (developer details / licenses)
repository(url: "file://${localReleaseDest}")
}
}
task zipRelease(type: Zip) {
from localReleaseDest
destinationDir buildDir
archiveName "release-${version}.zip"
}
task generateRelease << {
println "Release ${version} can be found at ${localReleaseDest}/"
println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip"
}
generateRelease.dependsOn(uploadArchives)
generateRelease.dependsOn(zipRelease)
我项目中的app.build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
// compile 'com.google.android.gms:play-services-identity:8.1.0'
// compile 'com.google.android.gms:play-services-gcm:8.1.0'
compile files('src/main/libs/custom_camera_gallery_library.jar')
}