APICloud 写模块坑点记录-相册开发

我最近写了一个图片选择的模块,里面包括拍照,选择图片,然后对图片进行压缩返回新压缩图片地址,只有android的,毕竟我不会IOS开发,弄这个图片选择模块感觉都快把我逼急了,但是经过后面慢慢磨,最后还是弄出来了
最后成果地址:https://github.com/caocao123/YaSuo

最开始我的代码写法是这样的
app的build.gradle

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/apiEngine v1.1.0.jar')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile project(':picaicompress')//我写的模块
}

picaicompress的build.gradle

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    provided files('../app/libs/apiEngine v1.1.0.jar')//引用app里面的lib
    //图片选择器的控件 https://github.com/lovetuzitong/MultiImageSelector
    compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
    compile 'com.android.support:appcompat-v7:23.4.0'
}

然后我就天真的去把这个picaicompress编译出aar文件,最后发现运行没有把MultiImageSelector里面的代码给放到aar文件里面。这个就让我很痛苦了,既然你没有把MultiImageSelector代码放进aar文件里面,那么我自己来放,我去吧MultiImageSelector编译成aar文件,放到picaicompress的lib里面进行引用

picaicompress的build.gradle

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    provided files('../app/libs/apiEngine v1.1.0.jar')
    //图片选择器的控件 https://github.com/lovetuzitong/MultiImageSelector
    compile(name:'multi-image-selector-release', ext:'aar')//引用aar文件
    compile 'com.android.support:appcompat-v7:23.4.0'
}

然后又编译成新的aar文件,还是没有用
最后我就想既然这样不行,我就你MultiImageSelector的代码全部copy到我的picaicompress代码里面来


APICloud 写模块坑点记录-相册开发_第1张图片
将代码copy过来.png

然后就开始运行编译成aar文件,发现竟然还是不可以,天啊,这是为啥呢?
后面我发现我自己的picaicompress里面也写了

compile 'com.android.support:appcompat-v7:23.4.0'

这样的代码,这样肯定不行啊,它这里面的代码不会一起编译到aar文件里面的
怎么办呢,后面我就去官网把android-support-v4.jar包下载下来,替换了上面的
picaicompress的build.gradle

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    provided files('../app/libs/apiEngine v1.1.0.jar')
    //图片选择器的控件 https://github.com/lovetuzitong/MultiImageSelector
    compile(name:'multi-image-selector-release', ext:'aar')//引用aar文件
    provided files('libs/android-support-v4.jar')//加入了这个
}

结果运行,天,不能运行了!!,返现的错误是各种跟v4冲突的文件。
然后我就采用这样的方式来写

 compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/apiEngine v1.1.0.jar')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile(project(':picaicompress')) {
        exclude group: 'com.android.support', module: 'support-v4'//剔除重复包
    }

结果还是不行,还是有冲突,冲突还是跟这个有关系

compile 'com.android.support:appcompat-v7:23.4.0'

我后面就把compile 'com.android.support:appcompat-v7:23.4.0'删除了
结果导致了,app style.xml里面的AppThme出错了,然后我就修改style.xml里面的风格


这样一编译发现可以哦
此时的样式
app build.gradle

 compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/apiEngine v1.1.0.jar')
    compile(project(':picaicompress')) {
        exclude group: 'com.android.support', module: 'support-v4'//剔除重复包
    }

picaicompress的build.gradle

    compile fileTree(include: ['*.jar'], dir: 'libs')
    provided files('../app/libs/apiEngine v1.1.0.jar')
    provided files('libs/android-support-v4.jar')//加入了这个

然后编译成aar文件放到APICloud里面,编译出APPLoader,结果编译不通过,错误日志如下:

/uzmap/temp/m1leaBvI0qCn92P/AStudioProject/app/src/main/AndroidManifest.xml:33: Error: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode]
    
                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~
   Explanation for issues of type "HardcodedDebugMode":
   It's best to leave out the android:debuggable attribute from the manifest.
   If you do, then the tools will automatically insert android:debuggable=true
   when building an APK to debug on an emulator or device. And when you
   perform a release build, such as Exporting APK, it will automatically set
   it to false.
   If on the other hand you specify a specific value in the manifest file,
   then the tools will always use it. This can lead to accidentally publishing
   your app with debug information.
1 errors, 0 warnings
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/IntegerRes.class
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

这里看的我头都晕了,后面我就想了想,是不是这个v4包不能在picaicompress的lib里面,我觉得可能,马上去修改,最最最最后成型的效果如下
app build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 24
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.gaoxx.yasuo"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets{
        main{
            jniLibs.srcDirs = ['libs']
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/apiEngine v1.1.0.jar')
    compile project(':picaicompress')
    compile files('libs/android-support-v4.jar')
}

picaicompress build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    provided files('../app/libs/apiEngine v1.1.0.jar')
    //图片选择器的控件 https://github.com/lovetuzitong/MultiImageSelector
    // compile 'com.github.lovetuzitong:MultiImageSelector:1.2'
    provided files('../app/libs/android-support-v4.jar')//我把v4的放到app的lib里面
}

OVER!!!!!!!

总结:
1、我发现他们APPCloud开发人员,写的那些模块都是eclipse开发出来的,引用android的包呢也就只有android-support-v4的包,然后我还跟appcompat-v7弄混了,我一直以为appcompat_v7android-support-v4一样的都可以是jar包,因为我看到这样的一句话:"V7里面是包含V4的"所以我一直找V7包,然后又想为啥APICloud不导入V7包呢,非要使用V4包呢,哎,真是尴尬啊我。不过我希望官方的尽快出android studio的版本出来
2、将所有你需要的代码都写到你的lib包里面,不要去通过引用第三方的,否则编译成aar文件的时候,不会把第三方的代码编译进去,你需要把代码copy过来放到项目里面

你可能感兴趣的:(APICloud 写模块坑点记录-相册开发)