2016-07-22 121 views
3

我对Android非常陌生,正在尝试一个简单的应用程序,在该应用程序中拍摄照片并将其发送给其他活动进行编辑。我正在使用Android Studio和OpenCV 3.1。一切正常。但后来当我开始写第二个活动的代码,它没有与下面的错误在我的平板电脑安装APK:Android Studio试图安装apk时出错

The currently selected variant "x86-debug" uses split APKs, but none of the 1 split apks are compatible with the current device with density "-1" and ABIs "". Error while Installing APK

奇怪的是,该活动正在就叫我修改了之前onCreate方法。思考我搞砸了一些东西,我禁用了一切,清理并再次尝试。现在,该应用拒绝安装,即使它处于与一切正常工作时相同的状态。

我的第二个活动如下:

public class SecondaryActivity extends Activity{ 

    public static final String PHOTO_MIME_TYPE = "image/png"; 
    public static final String EXTRA_PHOTO_URI = "com.example.morpheus.myapplication.SecondaryActivity.extra.PHOTO_URI"; 
    public static final String EXTRA_PHOTO_DATA_PATH = "com.example.morpheus.myapplication.SecondaryActivity.extra.PHOTO_DATA_PATH"; 
    private Uri mUri; 
    private String mDataPath; 
    private Mat photo; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     final Intent intent = getIntent(); 
     long addr = intent.getLongExtra("img_addr", 0); 
     photo = new Mat(addr); 

     mUri = intent.getParcelableExtra(EXTRA_PHOTO_URI); 
     mDataPath = intent.getStringExtra(EXTRA_PHOTO_DATA_PATH); 

     final ImageView imageView = new ImageView(this); 
     imageView.setImageURI(mUri); 

     setContentView(imageView); 

    } 
} 

的地方,上述活动被称为是:

 final ContentValues values = new ContentValues(); 
     values.put(MediaStore.MediaColumns.DATA, photoPath); 
     values.put(MediaStore.Images.Media.MIME_TYPE, SecondaryActivity.PHOTO_MIME_TYPE); 
     values.put(MediaStore.Images.Media.TITLE, appName); 
     values.put(MediaStore.Images.Media.DESCRIPTION, appName); 
     values.put(MediaStore.Images.Media.DATE_TAKEN, currentTime); 

     File album = new File(albumPath); 
     if(album.isDirectory() && !album.mkdirs()){ 
      Log.e(TAG, "Failed to create album directory at " + albumPath); 
      onTakePhotoFailed(); 
      return; 
     } 
     Imgproc.cvtColor(rgba, mBGR, Imgproc.COLOR_RGBA2BGR, 3); 
     if(!Imgcodecs.imwrite(photoPath, mBGR)){ 
      Log.e(TAG, "Failed to save photo to " + photoPath); 
      onTakePhotoFailed(); 
     } 
     Log.d(TAG, "Photo saved successfully to " + photoPath); 

     Uri uri; 
     try{ 
      uri=getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
     } catch (final Exception e){ 
      Log.e(TAG, "Failed to insert photo into MediaStore"); 
      e.printStackTrace(); 
      File photo = new File(photoPath); 
      if(!photo.delete()){ 
       Log.e(TAG, "Failed to delete non-inserted photo!"); 
      } 

      onTakePhotoFailed(); 
      return; 
     } 

     final Intent intent = new Intent(this, SecondaryActivity.class); 
     intent.putExtra(SecondaryActivity.EXTRA_PHOTO_URI, uri); 
     intent.putExtra(SecondaryActivity.EXTRA_PHOTO_DATA_PATH, photoPath); 
     long addr = mBGR.getNativeObjAddr(); 
     intent.putExtra("img_addr", addr); 

     startActivity(intent); 
    } 

最奇怪的是,即使恢复代码的地步后,它的工作,它不是安装。我尝试从平板电脑手动卸载应用程序。但这也没有帮助。

我正在使用带有英特尔凌动处理器的华硕ZenPad 8。

任何帮助将不胜感激,因为我的整个项目卡住了,因此。

回答

2

这可能与NDK和Build Variants有关:

Build Variants

人JUCE社区有办法解决这个问题,更多的Android Studio tips, tricks & known issues

至于侧面说明,尽量在你的应用程序的build.gradle用下面的代码分裂您的APK各自的变种:

apply plugin: 'com.android.application' 

android { 

    compileSdkVersion 23 
    buildToolsVersion "23.0.1" 
    ... 
    ... 

    // Split APK Start here 
    splits { 
    abi { 
     enable true 
     reset() 
     include 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips' 
     universalApk true 
    } 
    } 

    project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9] 

    android.applicationVariants.all { variant -> 
    variant.outputs.each { output -> 
     output.versionCodeOverride = 
      project.ext.versionCodes.get(output.getFilter(
       com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode 
    } 
    } 
    // Split APK End here 
    ... 
    ... 
} 

它会给你APK每个架构,也将让您的APK小。

+0

构建变体设置为x86Debug。我的应用程序的build.gradle中确实有一个“风格”设置。但是,谢谢你的提示!看起来这样更有效率。 –

相关问题