diff --git a/bin/templates/cordova/lib/pluginHandlers.js b/bin/templates/cordova/lib/pluginHandlers.js index 5b37bcaf34..2a6c0cfce3 100644 --- a/bin/templates/cordova/lib/pluginHandlers.js +++ b/bin/templates/cordova/lib/pluginHandlers.js @@ -326,6 +326,14 @@ function getInstallDestination (obj) { return path.join(obj.targetDir, path.basename(obj.src)); } else if (obj.src.endsWith('.java')) { return path.join(APP_MAIN_PREFIX, 'java', obj.targetDir.substring(4), path.basename(obj.src)); + } else if (obj.targetDir.includes('libs')) { + if (obj.src.endsWith('.so')) { + return path.join(APP_MAIN_PREFIX, 'jniLibs', obj.targetDir.substring(5), path.basename(obj.src)); + } else { + return path.join('app', obj.targetDir, path.basename(obj.src)); + } + } else if (obj.targetDir.includes('src/main')) { + return path.join('app', obj.targetDir, path.basename(obj.src)); } else { // For all other source files not using the new app directory structure, // add 'app/src/main' to the targetDir diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js index 71137fb5f6..0dd380a346 100644 --- a/spec/unit/pluginHandlers/handlers.spec.js +++ b/spec/unit/pluginHandlers/handlers.spec.js @@ -143,35 +143,35 @@ describe('android project handler', function () { }); it('Test#006f : should allow installing aidl file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + // NOTE: target-lib mapping for aidl is NOT included in 7.1.x + // in order to avoid an already "exists" installation error on + // https://github.com/j3k0/cordova-plugin-purchase#master + // (v7.2.4) in a patch release of cordova-android. android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/myapi.aidl', temp, path.join('app/src/main/src/com/mytest/myapi.aidl'), false); }); - it('Test#006g : should allow installing aar lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006g : should allow installing aar lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/testaar2.aar', temp, - path.join('app/src/main/libs/testaar2.aar'), false); + path.join('app/libs/testaar2.aar'), false); }); - it('Test#006h : should allow installing jar lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006h : should allow installing jar lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/testjar2.jar', temp, - path.join('app/src/main/libs/testjar2.jar'), false); + path.join('app/libs/testjar2.jar'), false); }); - it('Test#006i : should allow installing .so lib file from sources with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#006i : should allow installing .so lib file from sources with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); expect(copyFileSpy).toHaveBeenCalledWith(dummyplugin, 'src/android/jniLibs/x86/libnative.so', temp, - path.join('app/src/main/libs/x86/libnative.so'), false); + path.join('app/src/main/jniLibs/x86/libnative.so'), false); }); }); @@ -360,31 +360,31 @@ describe('android project handler', function () { }); it('Test#019f : should remove stuff by calling common.removeFile for Android Studio projects, of aidl with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + // NOTE: target-lib mapping for aidl is NOT included in 7.1.x + // in order to avoid an already "exists" installation error on + // https://github.com/j3k0/cordova-plugin-purchase#master + // (v7.2.4) in a patch release of cordova-android. android['source-file'].install(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[6], dummyPluginInfo, dummyProject, {android_studio: true}); expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/src/com/mytest/myapi.aidl')); }); - it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019g : should remove stuff by calling common.removeFile for Android Studio projects, of aar with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[7], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/testaar2.aar')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/testaar2.aar')); }); - it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019h : should remove stuff by calling common.removeFile for Android Studio projects, of jar with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[8], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/testjar2.jar')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/libs/testjar2.jar')); }); - it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme - reproduces GH-547', function () { - // reproduces GH-547 + it('Test#019i : should remove stuff by calling common.removeFile for Android Studio projects, of .so lib file with old target-dir scheme (GH-547)', function () { android['source-file'].install(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); android['source-file'].uninstall(valid_source[9], dummyPluginInfo, dummyProject, {android_studio: true}); - expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/libs/x86/libnative.so')); + expect(removeFileSpy).toHaveBeenCalledWith(temp, path.join('app/src/main/jniLibs/x86/libnative.so')); }); });